Leaving site page in PHP
When linking to an external site you can display a message to the user telling them that the link does not reside on your website.
<a href="?address=http://www.website1.com" target="_blank">External Link 1</a>
<a href="?address=http://www.website2.com" target="_blank">External Link 2</a>
<a href="?address=http://www.website3.com" target="_blank">External Link 3</a>
<a href="?address=http://www.website4.com" target="_blank">External Link 4</a>
These links do not link directly to a website but create a query string address that gives the address of the website.
$address = (string) $_GET['address'];
$fsock = fsockopen(str_replace('http://','',$address));
Now that we have the address we try to open it with the function fsockopen
.
if( !$fsock)
echo 'Address not valid.';
If we cannot open the address then we will alert the user.
else
{
echo 'Are you sure you want to leave this site?<br />';
echo 'Destination: <strong>'.$address.'</strong><br />';
echo '<a href="'.$address.'">Proceed</a>';
}
echo '<a href="javascript:window.close();">Close Window</a>';
Otherwise we display a link to the user and a message telling the user that this link is not within this website.