cybernet Posted January 25, 2012 Share Posted January 25, 2012 <?php // plm require_once (dirname(__FILE__) . "/inc/main.php"); $lang = load_language('view_post'); $id = intval($_GET['id']); if ( $id >= 1 ) { dbconn(); // la la la } else { echo "$id\n"; // for debugging die ("no id specified"); } ?> when it's executed of curse i get "0 no id specified" 1. i dont get why i get 0 as a result even if the url is /x.php?id=204 2. in error.log i get PHP Notice: Undefined index: id in x.php i intend to inform that formerly the script was running smoothly on lighttpd webserver, now i use nginx ( so i wont use words ) i know that are people with more complicated things around here ... but still i'm struggling for 1 hour with this xxx thanks in advance btw : php version 5.3.x Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted January 25, 2012 Share Posted January 25, 2012 you should be checking if the $_GET variable isset before setting its value into a variable. really, intval() isn't necessary since the value will automatically be converted Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 25, 2012 Share Posted January 25, 2012 really, intval() isn't necessary since the value will automatically be converted Automatically converted to what? Quote Link to comment Share on other sites More sharing options...
cybernet Posted January 25, 2012 Author Share Posted January 25, 2012 now i added if(!isset($_GET["id"])) echo "id is not set\n"; and of curse the error is "id is not set" and i tried to access the page with and without the ?id= the error is the same ... Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 25, 2012 Share Posted January 25, 2012 Unless you are unsetting $_GET variables in main.php, the problem is most likely nginx. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 25, 2012 Share Posted January 25, 2012 Could something in an include()d file or function be overwriting the $_GET array? Quote Link to comment Share on other sites More sharing options...
Cobra23 Posted January 25, 2012 Share Posted January 25, 2012 PHP Notice: Undefined index: id in x.php Did you define the id in x.php file ? To me it sounds like the page that it is being sent to once executed, that is causing the problem. or maybe even the include file which is affecting it. Quote Link to comment Share on other sites More sharing options...
cybernet Posted January 25, 2012 Author Share Posted January 25, 2012 how can i defined it if not like this ? $id = intval($_GET['id']); i searched main.php and has no unset problems i even replace $id with $post_id still the same result Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 25, 2012 Share Posted January 25, 2012 The error is not because of $id, it is because of $_GET['id']. The error says that $_GET['id'] is undefined. Try commenting out the include and see if it works then. Quote Link to comment Share on other sites More sharing options...
spiderwell Posted January 25, 2012 Share Posted January 25, 2012 yup if you use $_GET or $_POST or $_SESSION to try and get a value for something that doesnt exist , you will get this error Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted January 25, 2012 Share Posted January 25, 2012 if the OP uses isset() as I have recommended, this will not be an issue. OP, as pika said, most likely something in your included file is overwriting the $_GET array. Try removing the required file for testing purposes and see if you still get the error. Quote Link to comment Share on other sites More sharing options...
cybernet Posted January 25, 2012 Author Share Posted January 25, 2012 full source <?php // plm // require_once (dirname(__FILE__) . "/inc/main.php"); // $lang = load_language('view_post'); if(!isset($_GET["post_id"])) echo "1/id is not set\n"; $post_id = intval($_GET['post_id']); if ( $post_id >= 1 ) { echo "2/yo good"; } else { echo "$post_id\n"; die ("3/no id specified"); } ?> output 1/id is not set 0 3/no id specified error.log 2012/01/25 17:16:16 [error] 24454#0: *11049871 FastCGI sent in stderr: "PHP Notice: Undefined index: post_id in /home/postlist/x/view_post.php on line 9" while reading response header from upstream, client: 127.0.0.1, server: google.ro, request: "GET /view_post.php?post_id=88 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fastcgi/php-fastcgi.socket:", host: "google.ro" Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted January 25, 2012 Share Posted January 25, 2012 full source <?php // plm // require_once (dirname(__FILE__) . "/inc/main.php"); // $lang = load_language('view_post'); if(!isset($_GET["post_id"])) echo "1/id is not set\n"; $post_id = intval($_GET['post_id']); if ( $post_id >= 1 ) { echo "2/yo good"; } else { echo "$post_id\n"; die ("3/no id specified"); } ?> output 1/id is not set 0 3/no id specified error.log 2012/01/25 17:16:16 [error] 24454#0: *11049871 FastCGI sent in stderr: "PHP Notice: Undefined index: post_id in /home/postlist/x/view_post.php on line 9" while reading response header from upstream, client: 127.0.0.1, server: google.ro, request: "GET /view_post.php?post_id=88 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fastcgi/php-fastcgi.socket:", host: "google.ro" and you have "post_id" on the query string correct? Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 25, 2012 Share Posted January 25, 2012 perhaps a 'look-see' of the code that is creating the GET variable Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted January 25, 2012 Share Posted January 25, 2012 perhaps a 'look-see' of the code that is creating the GET variable it's from the url.. Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 25, 2012 Share Posted January 25, 2012 try http://php.net/manual/en/function.get-defined-vars.php at the top of your script Quote Link to comment Share on other sites More sharing options...
jcbones Posted January 26, 2012 Share Posted January 26, 2012 2012/01/25 17:16:16 [error] 24454#0: *11049871 FastCGI sent in stderr: "PHP Notice: Undefined index: post_id in /home/postlist/x/view_post.php on line 9" while reading response header from upstream, client: 127.0.0.1, server: google.ro, request: "GET /view_post.php?post_id=88 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fastcgi/php-fastcgi.socket:", host: "google.ro" Yes, post_id is set in his query string. At the top of your script, place the following code: echo '<pre>' . print_r($_GET,true) . '</pre>'; Quote Link to comment Share on other sites More sharing options...
cybernet Posted January 26, 2012 Author Share Posted January 26, 2012 url /view_post.php?post_id=88 full source <?php // plm // require_once (dirname(__FILE__) . "/inc/main.php"); // $lang = load_language('view_post'); echo '<pre>' . print_r($_GET,true) . '</pre>'; if(!isset($_GET["post_id"])) echo "1/id is not set\n"; $post_id = intval($_GET['post_id']); if ( $post_id >= 1 ) { echo "2/yo good"; } else { echo "$post_id\n"; die ("3/no id specified"); } ?> output Array ( ) 1/id is not set 0 3/no id specified Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 26, 2012 Share Posted January 26, 2012 so it appears that the GET is not being passed. Try these two simple files. (point browser to myvar1.php) myvar1.php <?PHP ?> <a href="myvars.php?post_id=99"> click me</a> <?PHP ?> myvars.php <?PHP echo "<PRE>"; print_r($_GET); echo "</pre>"; ?> Quote Link to comment Share on other sites More sharing options...
sasa Posted January 26, 2012 Share Posted January 26, 2012 Ara you sure that your comp is free of malicious software? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 26, 2012 Share Posted January 26, 2012 You likely have a .htaccess rewrite rule that is not passing the get parameters. What is in any .htaccess files that are present? Quote Link to comment Share on other sites More sharing options...
mikosiko Posted January 26, 2012 Share Posted January 26, 2012 2012/01/25 17:16:16 [error] 24454#0: *11049871 FastCGI sent in stderr: "PHP Notice: Undefined index: post_id in /home/postlist/x/view_post.php on line 9" while reading response header from upstream, client: 127.0.0.1, server: google.ro, request: "GET /view_post.php?post_id=88 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fastcgi/php-fastcgi.socket:", host: "google.ro" a quick search of the error message and similar on the ngnix site shows several hits; some of them pointing to some bugs and/or configuration issues for ngnix/php fastcgi that could be the cause of the behavior... maybe worth to look there. Quote Link to comment Share on other sites More sharing options...
cybernet Posted January 26, 2012 Author Share Posted January 26, 2012 You likely have a .htaccess rewrite rule that is not passing the get parameters. What is in any .htaccess files that are present? nginx as webserver so .htaccess is useless even if it existed ( but doesn't ) Ara you sure that your comp is free of malicious software? i use centos 6 Notice: Undefined index: id in /home/postlist/x/view_post.php on line 12 line 12 $id = intval($_GET['id']); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 26, 2012 Share Posted January 26, 2012 It may not have a .htaccess file by name, but it does have configuration files that get loaded. Does your configuration that is responsible for triggering the fastcgi for .php files have the following - fastcgi_param QUERY_STRING $query_string; Quote Link to comment Share on other sites More sharing options...
cybernet Posted January 26, 2012 Author Share Posted January 26, 2012 every site on the server has include /etc/nginx/fastcgi_params; and the file contains fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param HTTPS $server_https; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.