Jaymin Sejpal Jaymin Sejpal - 4 months ago 7
PHP Question

Can't login through USer's credentials in php

I got following error when I was dealing with login script.

Undefined index: user_login in C:\xampp\htdocs\ss\home.php on line 3

header.inc.php: This is my home.php page where I want to redirect registered user after login. It throws an error saying that user_login variable is not defined as I've stated above.

header.inc.php

<?php
include("./inc/connect.inc.php");
session_start();
if(!isset($_SESSION["user_login"]))
{

}
else
{
header("location: home.php");
}
?>


home.php

<?php
include("./inc/header.inc.php");
echo $_SESSION['user_login'];
?>

Answer

Got it! I just need to set first session variables and then only I can use it.

<?php 
session_start();
if (!isset($_SESSION["manager"])) {
    header("location: admin_login.php"); 
    $sessionvalue=$_SESSION["manager];
    exit();
}

If anyone wants to use it on another page. Just start the session and extract the values from session variable or instead directly use session value.

<?php 
session_start();
echo $_SESSION["manager"];
//Instead
echo $sessionvalue;
?>
Comments