Forum Moderators: coopster

Message Too Old, No Replies

How do I fix this PHP Error?

         

blackout

10:21 pm on May 20, 2008 (gmt 0)

10+ Year Member



Hi, I'm getting a lot of php errors in my error log. Can someone please explain to me what I can change to make this go away? I know I can change php.ini to remove notices, but I'm just interested in how I can get the errors to stop.

Here are the errors:

PHP Notice: Undefined index: save
PHP Notice: Undefined index: dir
PHP Notice: Undefined index: media

The lines of code that are being referred to are:

$save =$_REQUEST['save'];
$dir = $_REQUEST['dir'];
$set = $_REQUEST['media'];

Any help would be appreciated.

StoutFiles

10:25 pm on May 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PHP Notice: Undefined index: save
When you use $_REQUEST["save"] and "save" is not a variable in the request.

ag_47

10:30 pm on May 20, 2008 (gmt 0)

10+ Year Member



The variables 'save', 'dir', and 'media' are not set. (i.e. Undefined/Null).
I believe $save, $dir and $set will be simply set to null.
You can check the existance of a variable using isset():

if( isset($_REQUEST['name']) ) ...

blackout

10:33 pm on May 20, 2008 (gmt 0)

10+ Year Member



I'm sorry, I don't understand. What can I change to make this stop happening?

The only other line that contains the save variable is this:

<a href="vid.php?media=<?=$vid?>&save=yes">

blackout

10:46 pm on May 20, 2008 (gmt 0)

10+ Year Member



Sorry, it also occurs here:

if ($save == 'yes') {
$file = "./$media";
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);
exit();
}

xnavigator

11:14 pm on May 20, 2008 (gmt 0)

10+ Year Member



change in:

if (isset($_GET['save']) AND $_GET['save'] == 'yes') {
$file = "./$media";
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);
exit();
} else {
echo 'error';
}

blackout

11:46 pm on May 20, 2008 (gmt 0)

10+ Year Member



I tried this, but when I run the script it says error at the top of the page.

ag_47

12:26 am on May 21, 2008 (gmt 0)

10+ Year Member



No, use this:

$save = ( isset($_REQUEST['save']) ) ? $_REQUEST['save'] : "";
$dir = ( isset($_REQUEST['dir']) ) ? $_REQUEST['dir'] : "";
$set = ( isset($_REQUEST['media']) ) ? $_REQUEST['media'] : "";

At the beginning of your script.

blackout

1:30 am on May 21, 2008 (gmt 0)

10+ Year Member



That fixed it. Thanks ag_47.