Sir I have following codes on login.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once("../includes/connectsql.php");
require_once("../includes/functions.php");
$error = false;
$cerror="";
$cur_id=0;
$cur_user="";
$cur_email="";
$mypass="";
if(isset($_POST['login'])){
$muser=clean($_POST['username']);
$mpass=clean($_POST['password']);
$mypass=SHA1($mpass);
if (!preg_match("/^[a-zA-Z0-9]+$/",$mpass)) {
$error = true;
$cerror="Password must contain only alphabets and space";
}
if(!filter_var($muser,FILTER_VALIDATE_EMAIL)) {
$error = true;
$cerror = "Please Enter Valid Email ID";
}
if ($error == false)
{
$query="select * from u_login where email ='".$muser."' and pass='".$mypass."'";
$result=sqlsrv_query($con,$query)or die ("Error". sqlsrv_errors($con)) ;
while($res = sqlsrv_fetch_array($result)) {
$cur_id=($res['id']);
$cur_user=($res['userid']);
$cur_email=($res['email']);
}
if(empty($cur_user)){
$cerror="Email or Password is invalid";
}
else
{
date_default_timezone_set('Asia/Karachi');
session_start();
$_SESSION['v'] = 'vikas';
$_SESSION['id'] = $cur_id;
$_SESSION['user'] = $cur_user;
$_SESSION['email'] = $cur_email;
$_SESSION["startTime"] = date('Y-m-d H:i:s');
header("location:../index.php");
}
}
}
?>
When I enter correct login then control moves to this php
header("location:../index.php");
But immediately goes back to login.php
what I am doing wrong?
At the top of index.php i have these codes
<?php
session_start();
include_once("includes/connectsql.php");
if(!isset($_SESSION['user']))
{
header("location: admin/login.php");
exit;
}
?>
I think session is created but page moves to login.php
Please help