Jump to content

[SOLVED] Notice Undefined index: reset/ Attempting to redirect, works, but get a notice


physaux

Recommended Posts

Full Header.php is:

<?php
$reset= false;
$reset= strip_tags($_GET["reset"]);   //THIS IS LINE 3
if(empty($reset))
$reset = false;
if($reset==NULL)
$reset=false;
if($reset==true){
session_destroy();
header( 'Location: index.php' ) ;
}
?>

 

and i get the "Notice":

Undefined index: reset in /Users/../header.php on line 3

 

What is going on? If you need more information, here is start and end of my main file, index.php

<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);

session_start();
require_once("includes/header.php");
require_once("includes/constants.php");

//...
?>
<a href="index.php?reset=true">CLICK HERE TO RESET AND DESTROY ALL DATA</a>

 

So i only get this error when i go to index.php

index.php?reset=true works for me, but the problem is later after it redirects me back to index.php, the "Notice" is displayed..

How do i fix this?? :confused:

It basically means that you're trying to access an array index that does not exist. In this case, if the GET variable "reset" is not given to your script via the URL, that nasty little warning will raise it's head. As a general rule, you should always check that incoming GET and POST variables exist BEFORE trying to use them.

 

<?php
$reset= false;
if(isset($_GET['reset'])){
$reset= strip_tags($_GET["reset"]);   //THIS IS LINE 3
}
if(empty($reset))
   $reset = false;
if($reset==NULL)
   $reset=false;
if($reset==true){
   session_destroy();
   header( 'Location: index.php' ) ;
}
?>

Archived

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

×
×
  • 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.