Skatecrazy1 Posted September 18, 2006 Share Posted September 18, 2006 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 https://forums.phpfreaks.com/topic/21108-problems-with-headers/ Share on other sites More sharing options...
Wintergreen Posted September 18, 2006 Share Posted September 18, 2006 You can't echo something to be displayed and then use the header function, at least that's what I've found Link to comment https://forums.phpfreaks.com/topic/21108-problems-with-headers/#findComment-93740 Share on other sites More sharing options...
ToonMariner Posted September 18, 2006 Share Posted September 18, 2006 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 https://forums.phpfreaks.com/topic/21108-problems-with-headers/#findComment-93742 Share on other sites More sharing options...
Skatecrazy1 Posted September 18, 2006 Author Share Posted September 18, 2006 Aha, works like a charm. thanks. Link to comment https://forums.phpfreaks.com/topic/21108-problems-with-headers/#findComment-93745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.