Integrating PHP with NginX

Like we want to fire a url like http://con/dir/images/a.png

and we want to redirect it PHP server(before the request your php server should be started at port 9000)

location /con/dir {
    fastcgi_pass   localhost:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /dir path to php file/my.php;
    include        fastcgi_params;
}

where
my.php is

<?php

include "any file if required.php";

//do what ever u want

// set headers
header("Content-Description: File Transfer");
header("Content-Type: $mtype");
//it will open file in pop up window
if ($values_array[2] == 'showinline') {
    header("Content-Disposition: inline; filename=\"$fname\"");
} else {
    header("Content-Disposition: attachment; filename=\"$fname\"");
}
header("Content-Transfer-Encoding: binary");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
header("Content-Length: " . filesize($file_path));

//download
ob_clean();
flush();
readfile($file_path);
exit;
?>

Case 2:To handle path Param
location ~ /aa/bb/([^/]*)/([^/]*)/(.*?)/eot/(.*)$ {
 
   add_header Path_cookie $cookie_csessionid;
    fastcgi_pass   localhost:9001;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  S:/content/server/useraccessauthorization/src/useraccessauthorization/learningaccessauthorization.php;
   #  fastcgi_param QUERY_STRING  md5=$1,timetoken=$2,folderPath=$3,fileName=$4;
   fastcgi_param PATH_INFO $1:$2:$3:$4;
    include        fastcgi_params;
}

At PHP server
$url_array=split(":",$_SERVER['PATH_INFO']);
echo("<br/>");
echo($url_array[0]);
echo("<br/>");
echo($url_array[1]);
echo("<br/>");
echo($url_array[2]);
echo("<br/>");
echo($url_array[3]);
echo("<br/>");
$auth_md5 = $url_array[0];
$auth_timetoken=$url_array[1];
$auth_folderPath=$url_array[2];
$auth_fileName=$url_array[3];

print_r($_COOKIE);
echo("<br/>");
echo($_COOKIE['csessionid']);
echo("<br/>");
echo("----------------------------------------------------");
echo("<br/>");



No comments:

Post a Comment