That IS the code. Obviously replace the URL with the right one.
PHP, however, is a bit hard in itself. Don't worry... not impossible.
First... it's a SERVER SIDE programming language. This means, in short, that, unlike javascript, which acts through the browser, the server outputs the script as just html. The browser never sees the PHP source. (<?php echo "<a>"; ?> would JUST output <a> into the source; that's it.)
This poses some weird issues, but, in short, it's nice, secure, and compatible with all systems* because it is parsed (interpreted/decoded/executed) by the server each time in the same way, not by the users' computers, which frequently vary.
The other piece about PHP is that, like with javascript when the browser much have javascript enabled, the server must have PHP both enabled and installed. Many servers do, though some don't. If you have admin access and wish to, you could install it.
Another simple thing, but a bit different is that PHP files (with an exception I get into because it involves modifying configuration files) MUST end with ".php", not ".htm", ".html", etc. Not to worry for you, though. It will act the same way, except for the filename. Browsers know that .php means, to them anyway, just another webpage.
Also, simlilar to javascript tags (kinda), PHP has special tags (as well as it's own syntax/language/commands within it). Each block you want to be interpreted as PHP must be within <?php ....... ?> tags. Fairly straight-forward.
PHP is very powerful, but, for this, you're just using a basic function.
What you need to do is:
1. Find the URL they came from... the "HTTP_REFERER" in PHP.
2. Check "IF" that meets the conditions you want
3. Then act on it, such as redirecting, etc.
Assuming there isn't something else unforseen that will affect this, the solution should be quite simple. Here's the PHP code, with comments. (Comments if you don't know are like sticky notes in a book you are reading... they aren't part of the text; they just help you understand it.) Feel free to remove the comments (anything like //this... at the end of a line) when you actually use the script (though they might be good to reference later).
PHP Code:
<?php //open PHP er... mode... whatever you want to call it.
$lasturl = $_SERVER['HTTP_REFERER']; //set the variable $lasturl to the, well, last url.
//the array $_SERVER[... has lots of config/system/page info, like this, etc.
if (strpos('oldpage.com',$lasturl)) { //if 'oldpage.com' exists anywhere within the variable
//strpos returns the position of it. It will return FALSE if not found,
//so... that means it will just skip the if
//if it continues, we know that it's from the old page, because it had 'oldpage.com' in it.
//using 'oldpage.com' makes sense due to variations (like http://www. or just http://)
header("Location: http://mynewpage.com"); //send out http header data (this is how in PHP)
//and then set the Location to http://mynewpage.com
//note that it must be a FULL url, not a local page like "error.htm"
} //end the if
//below, end PHP
?>
YOUR HTML GOES HERE. THE PHP SHOULD BE THE VERY! TOP OF THE PAGE!
The header output MUST come before any text or the browser won't be able to handle it. The http data comes first, then text.
And here's an easier way of writing it, without comments, compressed for less space:
PHP Code:
<?php if (strpos('oldpage.com',$_SERVER['HTTP_REFERER'])) { header("Location: http://mynewpage.com"); } ?>
(To simplify more, you could remove the braces - {} around the contents of the IF, but it's a good habit to leave them there. They are required if the IF lasts more than one line.)
I hope this is helpful.
Remember, before this will work you need what I mentioned above-- PHP installed/enabled, and the page to end with .php, etc.
Bookmarks