Headers and Redirects

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Headers and Redirects

Post by evilmonkey »

Hello.

I have a question about headers. At what point in the program are they sent? Here is my code:

Code: Select all

$query="INSERT INTO users (username, password, name, email, icq, msn, aim, location, interests, music) VALUES ('$username', '$password', '$name', '$email', '$icq', '$msn', '$aim', '$location', '$interests', '$music')";
$result=mysql_query ($query, $db);
echo "Submission successful, you have registered.";
header ("Location = index.php");
And this is the error:

Code: Select all

Warning: Cannot add header information - headers already sent by (output started at c:\apache\htdocs\pc-dna\logging.php:16) in c:\apache\htdocs\pc-dna\logging.php on line 24
How do I got about fixing this? Also, Is there some kind of a delay function in PHP? I want the user to be able to see the message before they are re-directed, kind of like PHPBB.

Thanks.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please read Sticky: Before Post Read: Warning: Cannot add header information
It's not a sticky thread for nothing.
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

All right thanks.

I have found the javascript way to be easier (posted at the bottom of the aforementioned topic), how about the delay? I want my users to have 3-5 seconds to read the error (or success) message.

Thanks, sorry for my stupidity.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

the page after submitting a new post here contains something like
<meta http-equiv="refresh" content="3;url=viewtopic.php?p=35597#35597">
it advises the client to load the document viewtopic.php... in three seconds. Most browsers support this
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Thanks Volka. I got it.

Again, I must apologize for my stupidity earlier.

Cheers!
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Not stupidity, just lack of information. :D
Post Reply