0

Im using PHP curl to sign into a Website, my code looks like this:

<?php  
$Luser = "";
$Lpass = "";

if(isset($_POST['username']) && isset($_POST['password']))
{
    $Luser = $_POST['username'];
    $Lpass = $_POST['password'];
    $L_info="http://registration.zwinky.com/registration/loginAjax.jhtmlusername=".$Luser."&password=".$Lpass;
    $zwinky_login_file = file_get_contents($L_info, true);
    if (substr($zwinky_login_file, 12, 1) == "u"){ $message = "Blank username!"; }
    if (substr($zwinky_login_file, 12, 1) == "p"){ $message = "Blank password!"; }
    if (substr($zwinky_login_file, 12, 1) == "w"){ $message = "Wrong user/pass combination!"; }
    if (substr($zwinky_login_file, 12, 1) == "s"){
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL , $L_info);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_COOKIEFILE, "sessions/".$Luser);
    curl_setopt($ch, CURLOPT_COOKIEJAR, "sessions/".$Luser);
    $response = curl_exec($ch);
    curl_close($ch);

    $_SESSION['username'] = $Luser;
    $_SESSION['password'] = $Lpass;

    header('Location: http://idane.me/start.html');
    }
    echo($message);
}
?>

But im getting a Error :

Warning: Cannot modify header information - headers already sent by (output started at /customers/2/9/0/idane.me/httpd.www/login.php:49) in /customers/2/9/0/idane.me/httpd.www/login.php on line 73

Line 73:

header('Location: http://idane.me/start.html');

Is there something wrong?

daniel.
  • 128
  • 1
  • 1
  • 10
  • possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – hindmost Sep 17 '14 at 12:03

1 Answers1

1

What about the line 49 ?

And you should add exit() after you header :

header('Location: http://idane.me/start.html');
exit();
Surfoo
  • 88
  • 1
  • 12
  • Line 49 is just the opening php tag – daniel. Sep 17 '14 at 12:02
  • Ho so you include this file in another file which is producing an output ? As soon as your PHP is displaying an output to the browser it sends headers which make any header modification afterward impossible => therefore an error is raised – MaxouMask Sep 17 '14 at 12:23
  • Ah ! You can't send html before header : http://php.net/manual/en/function.header.php _Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file._ – Surfoo Sep 17 '14 at 15:16