3

i m trying to redirect to attempt page if user fills incorrect information... on the other hand if attempt page got refreshed want it to be redirected on login page... i m using session for that...

if (isset($c))
{
    $q = mysql_query("select * from registeration where email='$a' and password='$b'");
    $r = mysql_num_rows($q);

    if($r)
    {
        $_SESSION["Authenticated"] = 1;
        $_SESSION['id'] = $a;
    }
    else
    {
        $_SESSION["Authenticated"] = 0;
        $_SESSION["att"] = 1;
    }

    if(isset($_SESSION["att"]))
    {
        header("location:attempt1.php");
    }
    else
    {
        session_write_close();
        header('location:profile.php');
    }
}

the above mentioned code is redirecting on attempt1.php but code on attempt1.php redirecting back to index.php

session_start();
if (!isset($_SESSION["att"]))
{
    echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php\">";
}

i want attempt1.php code to redirect on user on index.php if session is not set.. and destroy session on refresh or direct page load... so that direct access to this page results in redirection to index page please help friends..

ANSWER ANSWER ANSWER all the questions i asked i made silly mistakes... here in this question i had not started session wile storing session variables.... add the below code in first line of login script

session_start();
4

3 回答 3

8
//try this code  
<?php 
session_start();
  if (!isset($_SESSION["att"]))
   {
      header("location: index.php");
   }
?>
于 2013-10-16T12:46:27.347 回答
4

我认为如果会话不存在,您要求重定向,因为会话需要一个 ID,您应该能够检查:

if(!(session_id()) header("Location: /mypage.php");
于 2013-10-16T12:44:44.743 回答
2

尝试这个:

if(empty($_SESSION))
{
  header("Location: /mypage.php");
}
else
{
    // do something ....
}

- 谢谢

于 2013-10-17T11:58:56.350 回答