PHP:退出问题?

时间:2014-01-01 09:37:05

标签: php mysql

亲爱的所有兄弟姐妹们。最近我创建了一个项目网站。 Everthing工作正常,但问题是当我单击注销时出现以下错误页面。 我也在堆栈溢出中寻找同样的问题,然后我尝试了,但我的问题还没有解决。

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.6 

             **My PHP scripts for check LOGIN.PHP is:**

<?php  


    session_start();    


    $host="localhost"; // Host name

    $username="root"; // Mysql username

    $password=""; // Mysql password

    $db_name="fb"; // Database name

    $tbl_name="users"; // Table name    


    // Connect to server and select databse.

    mysql_connect("$host", "$username", "$password")or die("cannot connect");

    mysql_select_db("$db_name")or die("cannot select DB");    


    // username and password sent from form

    $name=$_POST['email'];

    $password=$_POST['pwd'];

//select data from database    


    $sql="SELECT * FROM $tbl_name WHERE usermail='$name' && userpasswd='$password'";

    $result=mysql_query($sql);    


    // Mysql_num_row is counting table row

    $count=mysql_num_rows($result);    


    // If result matched $myusername and $mypassword, table row must be 1 row    


    if($count==1){

        // Register $myusername, $mypassword and redirect to file "search.php"

        //session_register("$name");

        //session_register("$password");

        $_SESSION['usermail']= $name;

        $_SESSION['userpasswd']=$password;

        header("location:home.php");    
    }

    else {

        $msg = "Wrong Username or Password. Please retry";

        header("location:ErrorPage.html");      

    }

?>
                  **PHP script for HOME.HTML**
<?php

session_start();

require("checklogged.php");

?>
                  **My LOGOUT.PHP script is:**

<?php
session_start();
$_SESSION['usermail'] ='$name';
$_SESSION['userpasswd']='$password';
session_unset();
session_destroy();
header("Location: login.html");//This is my initial login page
?>

3 个答案:

答案 0 :(得分:2)

您收到404错误,这意味着您没有将home.html文件放在logout.php文件中。尝试将其更改为index.phplogin.php(如果有)

喜欢这个......

session_unset();
session_destroy();
header("Location: index.php"); //<-- Change here
?>

答案 1 :(得分:2)

使用header(),您最好使用完整的网址。或者,至少添加正斜杠:header("Location: /home.html");

答案 2 :(得分:1)

可能是对页面的引用不正确,即注销页面与主页不同的目录使用../如果需要则提供目录级别或使用完整的URL,如:

 header("Location: http://www.mysite.com/home.php");