Jump to content

$_GET will not retrieve value from URL


happyjack825

Recommended Posts

Hello,

I'm running PHP 5.2.9 on a local server to test my projects locally but for some reason using $_GET will not return the values in the URL and will throw an "Undefined Index" notice. If I upload the same script to my web host, it works as it should.

 

For example, on my local server, the URL I'm using for the test script is /new_file.php?name=Joe. Then, to retrieve the value of "name", I use this:

<?php 
$name = $_GET['name']; 
echo $name; 
?>

 

Which results in:

PHP Notice: Undefined index: name in .\new_file.php on line 1

 

If I check to see if "name" is defined the URL, I can evade the notice, but the value of "name" is still not retrieved from the URL:

<?php 
if (isset($_GET['name'])) {
	$name = $_GET['name']; 
} else {
	$name = '';
}
echo $name;
?>

 

I haven't made any modifications to php.ini and I've searched for hours on various forums and other web sites for a solution but I can't seem to find one... Any help at all would be greatly appreciated!

 

Thank you,

--Sean  :)

Link to comment
https://forums.phpfreaks.com/topic/166084-_get-will-not-retrieve-value-from-url/
Share on other sites

Ok, maybe I lied when I said I didn't play with php.ini :D. I tried toggling register_globals on and off because I read about that elsewhere but it didn't seem to help. It is off right now:

register_globals => Off

Even with register_globals on I get the same PHP notice.

 

Thanks!

The only reasons you would get that error is if the variable was being unset either by your code or by register_globals being on or if your page is being requested without ?name= on the end of the URL or you are doing something on the server such as URL rewriting that is not passing the $_GET variables.

Well the code I've posted is the entirety of the test script, so I know there's no other variables. I'm pretty sure it's an issue with $_GET but I couldn't figure out what it was. register_globals is definitely off. I'm positive the URL contains the correct information, here is an excerpt from the server log:

127.0.0.1 - - [15/Jul/2009:13:23:03] "GET new_file.php?name=Joe HTTP/1.1" 200 96 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)"

I'm just very stumped :confused:. Any other ideas? Let me know if I need to post more information.

 

I appreciate all the responses :). Thanks!

 

 

make the contents of the script:

<?php
  echo "This is what is in $_GET: ";
  print_r($_GET);
?>

 

i know it seems silly, but double check the file you are editing is in fact the file that is getting run on the webserver. i can't even tell you the number of times i've been editing the wrong copy of the file, or it wasn't uploading via FTP properly

@ rhodesa: I tried your code, this is the output (url: new_file.php?name=Joe):

This is what is in Array: Array ( )

 

@ PFMaBiSmAd: Nope, each time I request "new_file.php?name=Joe" it shows up in the log just once (with "?name=Joe" present, as it should be).

Nope, no .htaccess files, and I'm not sure what mod_rewrite is, so I'm going to assume not?

 

Output of that code:

p?name=Joe

PHP Notice: Undefined index: REQUEST_URI in new_file.php on line 3

Is that "p" before "?name=Joe" supposed to be there?

 

EDIT: I moved new_file.php to the root of the server... the output changed to this:

name=Joe

PHP Notice: Undefined index: REQUEST_URI in new_file.php on line 3

But my original script still does not work from its new location...

 

EDIT 2: Should I change the location of the root directory for server? As it stands now it is C:\Users\Sean\Web Design.

that p? is weird and shouldn't be there. when it's in the root folder, can you echo $_GET['name'] ?

 

i also found it weird that REQUEST_URI isn't set...the output of those two lines of code should look like:

name=Joe
/path/to/new_file.php?name=Joe

$_GET still won't cooperate from the root, which is where I'm testing things from. I changed the location of the root from "C:\Users\Sean\Web Design" to "C:\server" with no change in results, so the root is now back to "C:\Users\Sean\Web Design". That weird "p?" doesn't show up when new_file.php is in the root (as it is now).

 

Unfortunately I won't be back until tonight... but thank you guys very much for the assistance so far!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.