Notice: Undefined index:

Hi everyone.
I am using session authorisation in a php website I am developing.
The sessions are being stored fine in the global variable $_SESSION[‘authorisation’] which is why I am a bit stumped.

I get the correct output from my echo statements below.
When it echos “Logged in user” the Notice: Undefined index lines do not appear, only when the user is not logged in they appear.

Can anyone help me?
Please find the errors and code I am using below.

Notice: Undefined index: authorisation in C:\xampp\htdocs\Scorer\matches.php on line 42
Notice: Undefined index: authorisation in C:\xampp\htdocs\Scorer\matches.php on line 44

[php]session_start();
if ($_SESSION[‘authorisation’] == ‘knownuser’){ <----- Line 42
echo “

Logged in user

”;
} elseif ($_SESSION[‘authorisation’] != ‘knownuser’) { <----- Line 44
echo “

Not logged in user

”;
}[/php]

Just ignore it, its just telling that it sees the session before its being used. The host shouldn’t have error reporting on. Unless its screwing up the layout, don’t worry about it.

Sometimes you just have to use a variable to get around this error.
Try:
[php]
session_start();
$authorisation = $_SESSION[‘authorisation’];
if ($authorisation == ‘knownuser’){
echo “

Logged in user

”;
} else {
echo “

Not logged in user

”;
}
[/php]
Else, you will have to alter your PHP error displays as Richei mentioned. (I only had this issue once and the variable useage made it go away, so not sure if it will help…)

[php]
if (isset($_SESSION[‘authorisation’]) && $_SESSION[‘authorisation’] == ‘knownuser’) {
echo “

Logged in user

”;
}
else {
echo “

Not logged in user

”;
}
[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service