0

Possible Duplicate:
PHP: Notice: Undefined index where the session variable is defined
PHP: “Notice: Undefined variable” and “Notice: Undefined index”

Ok, so this is the Error:

Notice: Undefined index: overview_id in C:\xampp\htdocs\site\home.php on line 6

And this is my code:

 <?php session_start();

   $sess = $_SESSION["overview_id"];

   if(isset($sess)){
     header("Location: account.php");
   }

 ?>

Any help would be cool.

Thank you.

Community
  • 1
  • 1
user1801600
  • 9
  • 1
  • 1
  • 1
  • $_SESSION["overview_id"] is not defined. just like the error message said –  Nov 05 '12 at 23:31
  • 1
    This isn't an error, its a *Notice*, it's just informing you of some nice-to-dos – Mitch Dempsey Nov 05 '12 at 23:32
  • I don't get it: if you check whether that `overview_id` element is defined (and you DO check it, with `isset`), why do you create a temporary variable, assign this value to it and only then check this variable? Why don't just `if(isset($_SESSION['overview_id']))` then? I mean, what's the reasoning behind this logic? – raina77ow Nov 05 '12 at 23:36

4 Answers4

0

Just change your third line to

if (isset($_SESSION['overview_id'])){

Instead and remove the second line.

jtheman
  • 7,421
  • 3
  • 28
  • 39
0

you set up session_id before checking, so it always must have at least default value assigned before You set up it to another variable, so better use this

if(isset($_SESSION["overview_id"])){
    header("Location: account.php");
}
DTukans
  • 339
  • 2
  • 7
0

In terms of the code that you have presented:

<?php 
session_start();

if(isset($_SESSION["overview_id"])){
    header("Location: account.php");
}

?>

This would resolve the issue

cEz
  • 4,932
  • 1
  • 25
  • 38
0

since $_SESSION["overview_id"] is not set, then $sess = $_SESSION["overview_id"]; will fail. This is how you have to do your test:

<?php session_start();

    if (isset($_SESSION["overview_id"])) {
        header("Location: account.php");
    }
?>
Greeso
  • 7,544
  • 9
  • 51
  • 77