Cookie工作本地,但不是在线PHP MYSQL

时间:2014-03-12 19:14:31

标签: php mysql cookies login admin

我正在使用登录系统,如果您以这样的方式登录,则会获得cookie:

此代码位于login.php:

if ($_SESSION['admintype']=="Admin") { 
        setcookie(Adminingelogd, date("F jS - g:i a"), $seconds);
        header("location:admin/E2/e2admin.php");
    } 

当您转到e2admin.php页面时,此代码就在上面:

if(!isset($_COOKIE['Admin'])) {
        header("location:../../index.php");
    }

因此,如果您没有cookie,您将发送回索引页面。 在我的本地服务器上一切正常,但当我上网并将其放在服务器上时,我收到一个错误:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at myURL/login.php:13) in myURL/login.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at MyURL/login.php:13) in MyURL/login.php on line 42

这是我的整个login.php文件。

<?php
    session_start();

    include "connect.php";

    $dbhandle = mysql_connect($hostname, $username, $password) or die("Kan niet inloggen");

    $selected = mysql_select_db("alexander_voetbalstats", $dbhandle);

    $myusername = $_POST['inlognaam'];
    $mypassword = $_POST['wachtwoord']; 

    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);

    $query = "SELECT * FROM users WHERE Username='$myusername' and Password='$mypassword'";
    $result = mysql_query($query);
    $count = mysql_num_rows($result);
    //$resultt = mysql_query($sql);

    mysql_close();

    if($count==1){
        $seconds = 9999 + time();
        $row = mysql_fetch_array($result);
        $_SESSION['admintype'] = $row['admintype'];

        if ($_SESSION['admintype']=="Admin") { 
            //setcookie(E2ingelogd, date("F jS - g:i a"), $seconds);
            header("location:admin/E2/e2admin.php");
        } 
        else if ($_SESSION['admintype']=="Visitor") { 
            //setcookie(adminingelogd, date("F jS - g:i a"), $seconds);
            header("location:nieuwegebruiker.php");
        }
        else {
            header("location:index.php");
}

    }else{
        echo 'Incorrect Username or Password';
    }
?>

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我的<?php标记上面有空格,这就是问题所在。

现在解决了!