If you need your PHP script to redirect to a different website, you can send an HTTP header to do that.

Remember, header() must be called before any actual output is sent, which includes not just HTML, but blank lines, etc.. as well.

566 Views
<?php

// Tell the web browser that the page has been moved to a new location

if (strpos(PHP_SAPI, 'cgi') === 0)
{
	// If CGI interface between web server and PHP
	header('Status: 301 Moved Permanently', true);
}
else
{
	header('HTTP/1.1 301 Moved Permanently', true, 301);
}


// Execute the redirect
header("Location: https://www.example.com/foo.html");

// Don't process or spit out anything in the script after this
die();
About the Author

I'm a super-geeky programmer with a passion for Internet marketing. :)