Sign in to follow this  
chbrules

[PHP] Issue w/ GET Variables

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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'];

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this