jump to navigation

Redirect using PHP and Javascript January 8, 2011

Posted by Tournas Dimitrios in PHP.

A function that redirects the user to the specified URL by sending the appropriate headers or by using JavaScript if the headers were already sent.

      function RedirectToUrl($ToUrl){

 // If an URL was passed

  if(strlen($ToUrl) > 0){

 // If headers were already sent, use JavaScript
 if(headers_sent()) {

 echo "<script type=\"text/javascript\">document.location.href=\"".$ToUrl."\";</script>\n";
   } else {    
// Sent redirect headers 
   header("Location: ".$ToUrl);








No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s