hi,
got a new prob, how can i create a php page that automatically refreshes each time i access the page.
iraberyl 0 Newbie Poster
Recommended Answers
Jump to Post<?php header("Location: http://yoursite.com/index.php"); exit; //above must be at very top before any browser output
Jump to PostWell actually the entire page will be process by php unless the exit; statement is placed there. So for example if you have a mysql insert it will insert before redirecting unless the exit; is placed immediatly after the header. And yes it will redirect the user to index.php however …
Jump to Postalso do we need to use the exit() below it?Will it ever get executed when already redirected to the header-location page?No it will get its turn to execute.
The exit function is used as a safety measure just in case the end user gets to echo something before header function …
Jump to Post…cwarn23 thanks for the elaboration.But are you trying to say that, the mysql insert will be executed in the below code as there is no exit after the header() -
if(something) { header("Location:new_url.php"); mysql_query($insert_query); }
compared to the code below -
if(something) { header("Location:new_url.php"); exit; mysql_query($insert_query); }
Jump to PostThis code will throw an error at line4 saying "headers already sent"
So no echoes before the header() :)Just to make it clear - indeed there should be no echos before the header().
All 19 Replies
leviathan185 14 Junior Poster
network18 15 Practically a Master Poster
iraberyl 0 Newbie Poster
network18 15 Practically a Master Poster
cwarn23 387 Occupation: Genius Team Colleague Featured Poster
iraberyl 0 Newbie Poster
venkat0904 1 Junior Poster
network18 15 Practically a Master Poster
cwarn23 387 Occupation: Genius Team Colleague Featured Poster
nav33n 472 Purple hazed! Team Colleague Featured Poster
network18 15 Practically a Master Poster
cwarn23 387 Occupation: Genius Team Colleague Featured Poster
venkat0904 1 Junior Poster
network18 15 Practically a Master Poster
nav33n 472 Purple hazed! Team Colleague Featured Poster
cwarn23 387 Occupation: Genius Team Colleague Featured Poster
network18 15 Practically a Master Poster
venkat0904 1 Junior Poster
iraberyl 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.