0

可能重复:
PHP 已发送的标头

我正在尝试设置一个简单的 php 用户名和密码登录。一切正常,直到我尝试重定向到 login_success.php 页面。所有信息都在下面,请帮助。

############### Code 
Warning: Cannot modify header information - headers already sent by (output started at              
.../edits/admon/minastotian/checklogin.php:4) in    
.../edits/admon/minastotian/checklogin.php on line 15

这是 checklogin.php 页面。它打印出上面的错误请帮助。谢谢你。

############### Code
<?php
    $host="i'm not telling"; // Host name 
    $username="db_user"; // Mysql username 
    $password="db_password"; // Mysql password 
    $db_name="db_name"; // 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 
    $myusername=$_POST['myusername']; 
    $mypassword=$_POST['mypassword']; 

    // To protect MySQL injection (more detail about MySQL injection)
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and     password='$mypassword'";
    $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 "login_success.php"
        $_SESSION['myusername'] = 'myusername';
        $_SESSION['mypassword'] = 'mypassword';
        header("location:login_success.php");
    }
    else {
        echo "Wrong Username or Password";
    }

   ?>

4

1 回答 1

0

标头是要发送的第一件事。如果您打印文本然后发送标题,它将显示类似的错误。删除或注释标题部分以查看是否正在打印错误

于 2012-06-12T01:02:50.303 回答