Ajax software
Free javascripts
↑
Main Page
This function verifies if the REFERER is from the local domain, and if it is, it doesn’t display the naviga-
tion link. If the REFERER is from any other domain, or if it is empty, the navigation link
is
displayed.
The function starts by telling if a REFERER does exist. If it doesn’t, you set a temporary variable, named
$display_nav
, to
true
. The default value of this variable is
false
. At the end of the function you ver-
ify its value and decide whether or not to display the navigation links:
// display popup navigation only when visitor comes from a SERP
function display_popup_navigation()
{
// display navigation?
$disp_nav = false;
// if there is no REFERER (visitor loaded popup directly), display navigation
if (!isset($_SERVER[‘HTTP_REFERER’]))
{
$disp_nav = true;
}
If there is a REFERER, you verify if the host name of the REFERER is the same one as the host of the
SITE_DOMAIN
constant, which you’ve defined in
config.inc.php
. If the host names are different, the
visitor arrived at the popup from an external web site, and you must display the navigation link:
// if the REFERER not from our domain, display navigation
else
{
// parse the REFERER and the local site using parse_url()
$parsed_referer = parse_url($_SERVER[‘HTTP_REFERER’]);
$parsed_local = parse_url(SITE_DOMAIN);
// extract the domain of the referer, and that of the local site
$referer_host = $parsed_referer[‘host’];
$local_host = $parsed_local[‘host’];
// display navigation if the REFERER URL is not from the local domain
if ($referer_host != $local_host)
{
$disp_nav = true;
}
}
In the end, if
$disp_nav
is
true
, you display the navigation link:
// display navigation if necessary
if ($disp_nav == true)
{
echo ‘<a href=”catalog.html”>Visit our catalog page!</a>’;
}
128
Chapter 6: SE-Friendly HTML and JavaScript
c06.qxd:c06 10:55 128
Ajax software
Free javascripts
→