Jump to content

problems with headers


Skatecrazy1

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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.