无法设置http_referer

时间:2013-02-04 08:12:03

标签: php http-referer

如何在登录后使用signin.php在http_referer页面中设置我的logout.php位置,并检查&成功登录重定向到joomla.php,我给了注销链接(使用href)现在我想点击注销&去看看。 php&我得到http_referer是joomla.php所以我可以设置logout.php

  1. 代码:Signin.php

    $referer = $_SERVER['HTTP_REFERER'];
    echo $referer;
    if ($referer == 'http://localhost/MinProject/reg.php')
    {
        echo "Registration SuccessFully";
    }
    
    else if($referer=='http://localhost/MinProject/changepassword.php')
    {
        echo"Change Password SuccessFully";
    }
    
  2. joomla.php

    <html>
        <body>
            <table width="100%">
                <tr>
                    <td width="20%" height="32" align="right" class="unm">
                        <?php
                        session_start();
                        if(isset($_SESSION['username']))
                        {
                            $name =$_SESSION['username'];
                            echo "Welcome ".$name;
                         }
                        ?>
                    </td>
                    <td width="64%" height="32" align="right">
                        <a href="changepassword.php">ChangePassword</a>
                    </td>
                    <td width="10%" align="right">
                        <a href="logout.php">logout</style></a>
                    </td>
                    <td width="11%"></td>
                    <td width="5%"></td>
                    <td width="5%"></td>
                    <td width="5%"></td>
                </tr>
            </table> 
        </body>
    </html>
    
  3. logout.php

    session_start();
    unset($_SESSION['username']);
    session_destroy();
    response.setHeader("Location: http://localhost/MinProject/logout.php");
    header("Location: Signin.php");
    exit();
    

1 个答案:

答案 0 :(得分:0)

HTTP_REFERER可能会被欺骗,因此您不应该使用它。

看看你的代码,我认为你正在努力实现。

$Message  = $_SESSION['MESSAGE'];//set the message Registration SuccessFully if registration else set it as Change Password SuccessFully or accordingly
if (isset($Message) and userhasidentity)
{
    echo $Message;
}else
{
   header('location:logout.php');
}