Jump to content

Archived

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

Skatecrazy1

problems with headers

Recommended Posts

Hi, i was trying to make a sort of IPB thing where it waits for a couple seconds then headers you back to the index page, but down where it says
[code]
echo ($msg);
sleep(3);
header("location:http://www.snapskate.com/index.php");
[/code]
i get this error
[quote]
Warning: Cannot modify header information - headers already sent by (output started at /home/content/s/n/a/snapskate/html/site/authenticate.php:30) in /home/content/s/n/a/snapskate/html/site/authenticate.php on line 32
[/quote]

i know this is kind of an easy error to fix, most likely, but I've been wading through all my code and I dont really know what's wrong, like I said it's probably just something I'm overlooking.

Anyway, here's the complete code for my authenticate.php file
[code]
<?php
$self = $_SERVER['PHP_SELF'];
$username = $_POST['username'];
$password = $_POST['password'];
$referer = $_SERVER['HTTP_REFERER'];

$conn = @mysql_connect("*****", "*****", "******") or die("Could not connect to the MySQL server.");

if( ( !$username) or ( !$password) )
  {
    header("Location:$referer");  exit();
  }

$rs = @mysql_select_db("snapskate", $conn) or die("Could not select the MySQL database.  Please try again.");

$sql = "select * from users where username=\"$username\" and password=\"$password\"";

$rs = @mysql_query($sql, $conn) or die("Could not execute the log in query.  Please try again.");

$num = mysql_num_rows($rs);


if($num != 0)
  {
setcookie( "loggedin", "1", time()+36000);
setcookie("username", $username, time()+36000);
$msg = "Thank You.  You are now logged in as $username. <br />You are now being transferred.<br /><br />";
$msg .= "<a href=\"http://www.snapskate.com/index.php\">Click here if you do not wish to wait</a>";
echo ($msg);
sleep(3);
header("location:http://www.snapskate.com/index.php");
  }  else {

header("location:$referer"); exit();
  }

?>

[/code]

thanks in advance for any help

Share this post


Link to post
Share on other sites
Correct Wintergreen...

headers cannot be sent once ANY output has been processed. That is any html (inlcuding whitespace -even if its before the doctype decalration!) that is echo or present after breaking out of php.

What you are trying to do is probably best achieved using the meta tag refresh method.

Share this post


Link to post
Share on other sites

×

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.