Jump to content


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


How to fix "undefined index: variable_name" error?

Recommended Posts


I need some help to diagnose and determine what is causing this problem and (most importantly) how to correct it.

Here is the error.  (I get a whole bunch just like this.. always the "undefined index: [i]variable_name[/i]"

[quote]PHP Notice:  Undefined index:  [b]pasv [/b] in C:\xxx_path_xxx\domain.org\zzzzz\autoinstaller.php on line 87[/quote]

Here is the code on line 87:

[code]if ($_GET['pasv'] == "on") { $_SESSION['ftp_passive'] = "on"; }[/code]

I believe the php error is caused because php is trying to "use" an undefined variable (called [i]pasv[/i]) for the first time, and the php config is somehow set to produce this warning.

This is becoming more and more common to see now, and it seems to happen when my users have to re-install PHP.  So I think there is some setting in a more recent "default' php installation which is causing this.

Does anyone have any idea what setting or configuration value can be set in PHP to "turn off" this warning?  (I tried setting the error_reporting(0); but that did not stop it.)

Or must I rewrite my entire PHP program to "declare" all variable before they are used?

Thanks for any help. 

Share this post

Link to post
Share on other sites
The problem is coming from the fact that you're requesting the [blah] value from the $_GET array, when there is no [blah] value you set.  If you want to avoid this error, which I believe isn't fatal and with the right error settings wouldn't display (ie production settings), then you should do the following:
if (isset($_GET[blah])) {
// do some stuff with the blah value
} else {
// maybe set blah?

Share this post

Link to post
Share on other sites


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.