Question

Im working with a login system where you get a cookie if you are logged in like this:

this code is on the login.php:

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

And when you go to the e2admin.php page this code is above:

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

So if you don't have the cookie you will send back to the index page. Everything is working fine on my local server but when i go online and put it on a server i'm getting an error:

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

And:

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

This is my whole login.php file.

<?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';
    }
?>

what am i doing wrong?

Was it helpful?

Solution

I had whitespace above my <?php tag that was the problem.

Solved now!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top