1

I have this code as shown bellow:

<?php
session_start();
require_once 'classes/cookie.class.php';
if(!isset($_SESSION['logged']) && !Cookie::checkCookie($_COOKIE['smt_auth']))
{
    header('Location: login.php');
    exit;
}

?>

It's working right in localhost, as it redirects always to login.php if the user is not logged, neither has a cookie. But the problem comes when I try to put these files in the host, it stops working.

The two files using this are index.php and temario.php, when I try to introduce the url of index.php it redirects me to login.php but, in temario.php, the screen just gets blank and doesn't redirect.

Both files have the same PHP block (there are no white spaces as I copy&pasted from index.php to temario.php), so does somebody know why this could not be working in the host, but it does on localhost with xampp?

It's throwing the error:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /homepages/3/d507876316/htdocs/new/usuario/temario.php:1) in /homepages/3/d507876316/htdocs/new/usuario/temario.php on line 4

Also if I make a copy of index.php and rename it, it also works as intended.

Thanks in advance.

ekostadinov
  • 6,880
  • 3
  • 29
  • 47
Xabi
  • 159
  • 1
  • 3
  • 13
  • check this once http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – sasi kanth Sep 10 '14 at 11:55
  • try this at place of header echo '' – john Sep 10 '14 at 11:56
  • 1
    As the error message says, there is some kind of browser output at the beginning of temario.php. If you cant see anything, just delete and retype the opening ` – Steve Sep 10 '14 at 11:58

2 Answers2

1

You need to session_start a cookie set before any body content sent to browser. So check if you have any echo, plain html or even whitespace before your code block. Also check for whitespaces before and after php tags. You should omit php end tags on end of php files.

0

Try after putting, <?php ob_start(); ?> at the beginning of code and <?php ob_flush(); ?> at the end of the page where you are writing header redirection code.

coDe murDerer
  • 1,858
  • 4
  • 20
  • 28