Jump to content

How to fix "undefined index: variable_name" error?


hstraf

Recommended Posts

Hello,

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. 
Link to comment
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:
[code]
if (isset($_GET[blah])) {
// do some stuff with the blah value
} else {
// maybe set blah?
}
[/code]
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.