[PHP] Issue w/ GET Variables

Started by
4 comments, last by chbrules 18 years, 10 months ago
Whenever I try to read a get variable while it's not in the URL it gives me a warning:
Notice: Undefined index: check in \xxxxxx\xxxxxx.php on line 11
Line 11 is:
$check = $_GET['check'];
I'm guessing it's some debug feature in PHP I haven't turned off on my server? I remember I used to be able to try to read it, if it isn't there then it'd be NULL and I'd do a check against it. Now I get stupid errors. =/ I'm using IIS w/ PHP 5. Thanks!
-Conrad
Advertisement
I haven't had much experiance with PHP5, but I do know that register_globals can mess around with some stuff. You could check the documentation (I'm assuming you already have).
Rob Loach [Website] [Projects] [Contact]
Quote:Original post by Rob Loach
I haven't had much experiance with PHP5, but I do know that register_globals can mess around with some stuff. You could check the documentation (I'm assuming you already have).


register_globals would have made the 'check' GET variable $check automatically.

The reason you're getting an index undefined error is because $_GET is an array. An associative array of key=value pairs that comes from your GET arguments. If the key "check" is not on the url, then it will not be in the array and thus the index in the array is undefined.

You will need to test it first..
$check=some default value;if(isset($_GET['check']))  $check = $_GET['check'];
That's right..., with PHP 4 that didn't happened but now PHP 5 compains about it....
Quote:Original post by haora
That's right..., with PHP 4 that didn't happened but now PHP 5 compains about it....


It could be the php.ini settings in 5 are slightly different. Check the "Error handling and logging" section in your php.ini file.. It contains decent documentation on how to change the settings for the error_reporting and display_errors settings.
Anyone know specifically how to shut it off or am I going hunting? I'll try that isset() check. Thanks!
-Conrad

This topic is closed to new replies.

Advertisement