Jump to content

the simplest thing in the world fails / LOL


cybernet

Recommended Posts

<?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

:wtf: ( 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 8)

btw : php version 5.3.x

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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"
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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  :D

 

Notice: Undefined index: id in /home/postlist/x/view_post.php on line 12
:confused:

 

line 12

$id = intval($_GET['id']);

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.