0

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?

AlexanderFT
  • 81
  • 1
  • 2
  • 13
  • So output was started at line 13. What is line 13 in your original script? I'm guessing a warning, perhaps about deprecated `mysql_*` functions. And you should really read up on sql injection. And never store plain-text passwords, always use a salted hash. – jeroen Mar 12 '14 at 19:25
  • So you have output before that. Remove that / put it after the header calls. – jeroen Mar 12 '14 at 19:29
  • Your code is vulnerable to SQL injections; you should read on [how to prevent them in PHP](http://stackoverflow.com/q/60174/53114). – Gumbo Mar 14 '14 at 09:51

1 Answers1

0

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

Solved now!

AlexanderFT
  • 81
  • 1
  • 2
  • 13