faqts : Computers : Programming : Languages : PHP : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

26 of 53 people (49%) answered Yes
Recently 3 of 10 people (30%) answered Yes


How go to another page or redirect from within a PHP script?

Dec 26th, 2005 04:40
Praveen Kumar Kukkapalli, Reza Fathi, Matt Gregory, Gary Chu,

You can use meta refresh tag.
<meta http-equiv="refresh" content="5;url=http://www.EruditeSoft.com">
It will foreard to the specified URL after 5 seconds.
You can find information on redirections at:
FAQTS : Computers : Programming : Languages : PHP : Common Problems : 
But I would attack this problem from a different angle:  Instead, after 
my code reached the point where I knew I wanted the user to go to a 
different page, I would call an include or require for that page and 
allow execution to continue from within the same run, simply pumping 
different output to the client.  
NOTE: this approach will not work if you have already sent output the 
client that you wish to replace with new output.
//There are few ways that you can do this in php
// here are couple of ways ... [email protected]
	echo  "<H1 align=\"center\">Update was successful</H1>";
	echo  "<H3 align=\"center\">Redirection in 5 seconds...</H3>";	
	echo "<SCRIPT language=\"JavaScript\">";
	echo "function delay(){";
	//echo "parent.frames.MainWin.history.back();";
	echo "parent.frames.MainWin.location.href='news.php';";
	echo "}";
	echo "setTimeout(\"delay()\", 5000);";
	echo "</script>";
	echo "<script language=\"JavaScript\">";
	echo "window.opener.location.reload(true);";
	echo "self.close();";
	echo "</script>";