0

So I am trying to integrate logging in via facebook in my website. Because people who do not wish to use facebook can use our website's logging in system, we have create a way to set cookies and sessions. There i want to create cookies and session variables for facebook users as well.
However, I get this error :

Warning: Cannot modify header information - headers already sent by (output started at /home/content/88/10590088/html/Test4/index.php:9) in /home/content/88/10590088/html/Test4/login.php on line 144

Warning: Cannot modify header information - headers already sent by (output started at /home/content/88/10590088/html/Test4/index.php:9) in /home/content/88/10590088/html/Test4/login.php on line 145

and line 145 and line 144 are the last 2 lines below:

// CREATE THEIR SESSIONS AND COOKIES
$_SESSION['userid'] = $db_id;
$_SESSION['username'] = $db_username;
setcookie("id", $db_id, strtotime( '+30 days' ), "/", "", "", TRUE);
setcookie("user", $db_username, strtotime( '+30 days' ), "/", "", "", TRUE);
Luís Ramalho
  • 10,018
  • 4
  • 52
  • 67

1 Answers1

0

The problem is that cookies and sessions are set by sending headers back to the browser.
You can find a great explanation about why this happens here.

You cannot modify the headers when there already sent, probably you have some HTML code or blank spaces between line 9 and line 144, try to remove them if there are any or try to move line 144-145.

Otherwise try using methods like ob_flush.(Place it just before line 144)

Community
  • 1
  • 1
  • Thank you but, I deleted the spacing I had and still the same error occurs. Also, the `ob_flush()` did not work. Just in case you did not realise, the line 9 is in another file called index.php and line 144-145 is from another file login.php. The line 9 in index.php `` – salonikaur Jul 19 '13 at 14:25