Jump to content


Photo

problems with headers


  • Please log in to reply
3 replies to this topic

#1 Skatecrazy1

Skatecrazy1
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 18 September 2006 - 12:21 AM

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
echo ($msg);
	sleep(3);
	header("location:http://www.snapskate.com/index.php");
i get this error

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


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
<?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();
   }

?>


thanks in advance for any help
fuck it or fight it

#2 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 18 September 2006 - 12:24 AM

You can't echo something to be displayed and then use the header function, at least that's what I've found

#3 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 18 September 2006 - 12:30 AM

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.
follow me on twitter @PHPsycho

#4 Skatecrazy1

Skatecrazy1
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 18 September 2006 - 12:34 AM

Aha, works like a charm. thanks.
fuck it or fight it




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users