发布后重定向如何工作?

发布于 2024-08-19 04:38:52 字数 3540 浏览 7 评论 0原文

可能的重复:
后退按钮重新提交表单数据 ($_POST)

有些人建议我宁愿编辑问题,将其作为新问题,这就是我这样做的原因...

<?php
session_start();

if(isset($_POST['username']) && ($_POST['password'])) 
{

                $con=mysql_connect("localhost","root","");
                if(!$con)
                {
                die('Could Not Connect:'.mysql_error());
                } 

                mysql_select_db("tcs",$con);

                $usr=$_POST["username"];                 //pick username from login page
                $pwd=hash('sha1',$_POST['password']);    //pick password from login page and use hash algorithm to encrypt it

                $query="select * from employee where Username='$usr' and Password='$pwd'";  //serch that single row in which both r found
                $result=mysql_query($query,$con);


                    if ($result) 
                    {

                                $row=mysql_fetch_array($result);

                        if (($row["Username"]==$usr) && ($row["Password"]==$pwd))
                        {

                                $_SESSION['employee']['id']=$row['User Id'];
                                $_SESSION['employee']['username']=$row['Username'];
                        }       
                        else
                        {
                                echo "Login Not Successfull";
                        }
                    }   
}

else
{
echo 'Error! Username & Password were not sent!';
}

$_SESSION['user_authenticated'] = true;

?>

<html>
<body bgcolor="black">


<?php 
if($_SESSION['user_authenticated']) 
{


                                echo "<font color=red>"."<h3 align=center>"."Welcome ".$_SESSION['employee']['username']."</h3>"."</font>";
                                echo "<br />"."<a href='upload_file.php'>"."<font color='white'>"."<h4>"."Up-Load Files"."</h4>"."<font>"."</a>";
                                echo "<br />"."<br />"."<a href='list_files.php'>"."<font color='white'>"."<h4>"."List All Up-Loaded Files"."</h4>"."<font>"."</a>";

}



?>

</font>
<a  href="logout_file.php"><font color="white"><h3 align="right">Sign Out</h3></font></a>
<font color="white">

</body>
</html>

好吧,现在我明白了。但是还有一个问题。假设我在登录操作页面上,其中有一个符号链接当我点击注销按钮时,我会被重定向到登录页面。好的,没问题,但如果我再次按后退按钮,我会被要求重新发送数据(即使在注销后),并且我会再次登录-实际操作页面为什么会这样。这是错误的..该怎么做。对于所有其他页面,例如我单击上传中的注销按钮 按钮 -> 重定向到登录,如果我按后退按钮,它会显示您已注销。我不知道如何检查会话变量退出以进行签名,

因为菲利克斯先生告诉我检查这个 http://www.thefutureoftheweb.com/blog/get-redirect-after-post

但我真的不明白这个人在说什么。很抱歉我不太懂技术,因为我是初学者我知道我面临什么问题...

据我所知

    if (count($_POST)) {             //checking how many time data is being resend.
        // process the POST data
   add_comment($_POST);        //what this function do i dont know 

   // redirect to the same page without the POST data
header("Location: ".$_SERVER['PHP_SELF']);  //i think it is like  
                                //refreshing without get input again from allpication form
        die;
    }

请解释一下,特别是这是什么 $_server(;PHP_SELF)

Possible Duplicate:
Back button re-submit form data ($_POST)

some guys suggest me rather then editing the question put it as new question that's why i am doing so...

<?php
session_start();

if(isset($_POST['username']) && ($_POST['password'])) 
{

                $con=mysql_connect("localhost","root","");
                if(!$con)
                {
                die('Could Not Connect:'.mysql_error());
                } 

                mysql_select_db("tcs",$con);

                $usr=$_POST["username"];                 //pick username from login page
                $pwd=hash('sha1',$_POST['password']);    //pick password from login page and use hash algorithm to encrypt it

                $query="select * from employee where Username='$usr' and Password='$pwd'";  //serch that single row in which both r found
                $result=mysql_query($query,$con);


                    if ($result) 
                    {

                                $row=mysql_fetch_array($result);

                        if (($row["Username"]==$usr) && ($row["Password"]==$pwd))
                        {

                                $_SESSION['employee']['id']=$row['User Id'];
                                $_SESSION['employee']['username']=$row['Username'];
                        }       
                        else
                        {
                                echo "Login Not Successfull";
                        }
                    }   
}

else
{
echo 'Error! Username & Password were not sent!';
}

$_SESSION['user_authenticated'] = true;

?>

<html>
<body bgcolor="black">


<?php 
if($_SESSION['user_authenticated']) 
{


                                echo "<font color=red>"."<h3 align=center>"."Welcome ".$_SESSION['employee']['username']."</h3>"."</font>";
                                echo "<br />"."<a href='upload_file.php'>"."<font color='white'>"."<h4>"."Up-Load Files"."</h4>"."<font>"."</a>";
                                echo "<br />"."<br />"."<a href='list_files.php'>"."<font color='white'>"."<h4>"."List All Up-Loaded Files"."</h4>"."<font>"."</a>";

}



?>

</font>
<a  href="logout_file.php"><font color="white"><h3 align="right">Sign Out</h3></font></a>
<font color="white">

</body>
</html>

Ok fine now i am getting the point.But there is one more problem.Suppose i am on signin-action page which have a link of sign out.When i click on sign out button i am re-directed to sign in page.ok no problem but again if i press back button again i am asked to resend the data(even after sign out) and again i am on sign-in-action page why so. It is wrong yar..What to do this.For all other pages like if i click on sign out button from upload
button->redirected to sign-in and if i press back button it shows u are signed out. I don't know how to check session variable exit for signinaction

as felix sir told me to check this http://www.thefutureoftheweb.com/blog/get-redirect-after-post

but really i am not getting what this guy is saying.I am sorry i am not so techanical becuase i am a begineer I know what problem i am facing...

as far as i know

    if (count($_POST)) {             //checking how many time data is being resend.
        // process the POST data
   add_comment($_POST);        //what this function do i dont know 

   // redirect to the same page without the POST data
header("Location: ".$_SERVER['PHP_SELF']);  //i think it is like  
                                //refreshing without get input again from allpication form
        die;
    }

Please, explain it, especially what is this $_server(;PHP_SELF)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新人笑 2024-08-26 04:38:52

关于 $_SERVER - 请参阅

About $_SERVER - see this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文