Sir I am using IIS Manager, as follows

Untitled2.png

and I have these codes for 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['usno']);
            $cur_user=($res['userid']);
            $cur_email=($res['email']);
        }  

        //echo $cur_use;
        if(empty($cur_user)){
            $cerror="Email or Password is invalid";
        }
        else
        {
            date_default_timezone_set('Asia/Karachi');
             session_start();
             //session_regenerate_id();

            $_SESSION['id'] = $cur_id;
            //          $_SESSION['logout'] = $row2['logout'];
            $_SESSION['user'] = $cur_user;
            $_SESSION['email'] = $cur_email;
            $_SESSION["startTime"] = date('Y-m-d H:i:s');
            var_dump($_SESSION);
        //  header("location:../index.php");
        //   session_write_close();
         //   exit();
        }

    }
}
?>

When I enter correct user name and password then following redirect line does not work

header("location:../index.php");  

I checked with

var_dump($_SESSION);  

it says:
 ![Untitled.png](/attachments/large/4/8835633042d9659ef4f6f3c9733414a5.png "align-center") 

What is this problem?

I think it is session problem.

Please help

Recommended Answers

All 3 Replies

Member Avatar for diafol

Put this at the top of every file that needs it: session_start();

DO NOT place any output (e.g. HTML / echo string / error msgs) before header(...);

Some things I would do to troubleshoot...

  1. var_dump($result); - validate your query results
  2. See if that .png file exists and what it is
  3. grep all of the code for "_SESSION" and "session_start()" to see if the session is started and/or managed elsewhere

I might be mistaken, but can you send an HTTP header specifying a Location: that is a relative URL?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.