How to avoid notice in php when one of the conditions is not true
Posted
by user225269
on Stack Overflow
See other posts from Stack Overflow
or by user225269
Published on 2010-05-25T10:41:52Z
Indexed on
2010/05/25
10:51 UTC
Read the original article
Hit count: 197
php
I've notice that when one of the two conditions in a php if statement is not true. You get an undefined index notice for the statement that is not true. And the result in my case is a distorted web page. For example, this code:
<?php
session_start();
if (!isset($_SESSION['loginAdmin']) && ($_SESSION['loginAdmin'] != '')) {
header ("Location: loginam.php");
} else {
include('head2.php');
}
if (!isset($_SESSION['login']) && ($_SESSION['login'] != '')) {
header ("Location: login.php");
} else {
include('head3.php');
}
?>
If one of the if statements is not true. The one that is not true will give you a notice that it is undefined. In my case it says that the session 'login' is not defined. If session 'LoginAdmin' is used. What can you recommend that I would do in order to avoid these undefined index notice.
© Stack Overflow or respective owner