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.

3
  • $_SESSION["overview_id"] is not defined. just like the error message said Commented Nov 5, 2012 at 23:31
  • 1
    This isn't an error, its a Notice, it's just informing you of some nice-to-dos Commented Nov 5, 2012 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? Commented Nov 5, 2012 at 23:36

4 Answers 4

0

Just change your third line to

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

Instead and remove the second line.

Sign up to request clarification or add additional context in comments.

Comments

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");
}

Comments

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

Comments

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");
    }
?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.