-1

i want to make change my default menus after login passed and I have some code for my app like this

index.php

<?php session_start(); ?>

<html>
<head></head>
<body>
<ul>
 <?php if($_SESSION['loggedIn'] == '1' ): ?>
<li><a href="../templates/"  title="Home" id="activated">Home</a></li>
<li><a href="catalog.html" title="Catalog" >Catalog</a></li>
<li><a href="signup-for-partners.html" title="Partners">Become Our Partner</a></li>
<li><a href="About-us.html" title="About Us">About Us</a></li>
   <?php else: ?>
   <li><a href="../templates/"  title="" >Home</a></li>
   <li><a href="account.html"  title="" >My Account</a></li>
   <li><a href="catalog.html" title="" >Catalog</a></li>
   <li><a href="logout.php" title="" >logout</a></li>
   <?php endif; ?>
  </ul>

</body> </html>

and this is my process with captcha

<?php

session_start();
include 'conection.php';


if($_POST['captcha'] == $_SESSION['captcha']){

    $username = $_POST['UserID'];
    $password =$_POST['Password'];

    $sql = "select * from login where username='".$username."' and password='".$password."'";
    #echo $sql."<br />";
    $query = mysql_query($sql) or die (mysql_error());

    if($query){
        $row = mysql_num_rows($query);

        if($row > 0){
            $_SESSION['loggedIn']='1';
            $_SESSION['UserID']=$username;
            header('Location: ../templates/');
        }
        else {
            header('Location: error.php');
        }
    }
}
else{ 

header('Location: ../templates/');


}
?>

and its appear error like this

Notice: Undefined index: loggedIn in C:\xampp\htdocs\Templates\index.php on line 78

the loggedIn just defined in process.php

why its not working?

1 Answers1

0

You have to test if your session exists with isset(), then if it's the good value :-)

if(isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == '1' ){ ... }

By the way, mysql_* is deprecated: You should use PDO or Mysqli Have a look : Why shouldn't I use mysql_* functions in PHP?

And, writing if($var == 1) and writing if($var) are the same thing: 1 can be a true, "1" as string, or 1 as int

Community
  • 1
  • 1
Thomas Rbt
  • 1,483
  • 1
  • 13
  • 26