Jump to content

Page redirection and eliminating warnings


daveeboi

Recommended Posts

From my script for a successful login on my site :

 

// Check if session is not registered , redirect back to main page.

<?
session_start();
if(!isset($_SESSION['myusername'])){
header("location:index.php");
}
else
{
  echo"Login Successful";
}
?>

 

I keep getting the following output :

 

// Check if session is not registered , redirect back to main page.

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/html/login_success.php:3) in /home/content/html/login_success.php on line 4

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/html/login_success.php:3) in /home/content/html/login_success.php on line 6

 

The page does not redirect to the pages I wish it to and it displays warnings that I can't seem to get rid of.

 

Any advice please?

Without seeing if this is a page in itself or not, I would say remove the whitespace.  Basically make the file like this:

 

<?
session_start();
// Check if session is not registered , redirect back to main page.
if(!isset($_SESSION['myusername'])){
header("location:index.php");
}
else
{
  echo"Login Successful";
}
?>

 

Notice there is no blank line before the <? tag.  also I just moved the comment below the session.

 

However if that code is actually below other code in the page, we would need to see that.  Header errors are almost always caused by unintended whitespace being show before php parses the script.

Thanks, that's got rid of the warnings and taken to a new page.  Unfortunately it's also taking my test login members as a failed login as well but that's in my checklogin.php file so off to try fix that now.

 

This forum is great for quick and reliable help, can't believe I've just found it.  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.