• Aucun résultat trouvé

Implementing Spiderable Popups

Dans le document Search Engine Optimization with PHP (Page 148-154)

1.

Add a link to your popup file in your catalog.phpscript, as highlighted in the following code snippet. Note that this assumes you’re working on the code that you built in the previous chap-ters. If you don’t have it ready, feel free to use the code download of this chapter.

<?php

// load the URL factory library

require_once ‘include/url_factory.inc.php’;

<a href=”<?php echo make_category_product_url(“Friends’ Shed”, 2, “PHP E-Commerce Book”, 42); ?>”>

<a href=”popup.php” target=”_blank”>Find more about Professional Search Engine Optimization with PHP!</a>

</center>

</body>

</html>

2.

Load http://seophp.example.com/catalog.htmlto ensure your script loads correctly and displays the new link, as shown in Figure 6-1. Note that this exercise assumes you have built your simple catalog as shown in Chapter 3.

Figure 6-1

3.

Create a new file named popup.phpin your seophpfolder, and type this code in:

<?php

// load the popup utils library

require_once ‘include/popup_utils.inc.php’;

?>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN”

“http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>

<html>

<head>

<title>Professional Search Engine Optimization with PHP: Table of Contents</title>

</head>

<body onload=”window.resizeTo(800, 600);”

onresize=’setTimeout(“window.resizeTo(800, 600);”, 100);’>

<h1>Professional Search Engine Optimization with PHP: Table of Contents</h1>

<?php

// display popup navigation only when visitor comes from a SERP display_navigation();

?>

<ol>

<li>You: Programmer and Search Engine Marketer</li>

<li>A Primer in Basic SEO</li>

<li>Provocative SE-Friendly URLs</li>

<li>Content Relocation and HTTP Status Codes</li>

<li>Duplicate Content</li>

<li>SE-Friendly HTML and JavaScript</li>

<li>Web Syndication and Social Bookmarking</li>

<li>Black Hat SEO</li>

<li>Sitemaps</li>

<li>Link Bait</li>

<li>IP Cloaking, Geo-Targeting, and IP Delivery</li>

<li>Foreign Language SEO</li>

<li>Coping with Technical Issues</li>

<li>Case Study: Building an E-Commerce Catalog</li>

<li>Site Clinic: So You Have a Web Site?</li>

<li>WordPress: Creating a SE-Friendly Weblog?</li>

<li>Introduction to Regular Expressions</li>

</ol>

</body>

</html>

4.

Create a new file named popup_utils.inc.phpin your seophp/includefolder, and write this code:

<?php

// include config file

require_once ‘config.inc.php’;

// 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 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;

} }

// display navigation if necessary if ($disp_nav == true)

{

echo ‘<a href=”catalog.html”>Visit our catalog page!</a>’;

} }

?>

5.

This is the moment of truth. Load http://seophp.example.com/catalog.html, and click the popup link. No navigation should show up. If you get to the popup page through Google, Yahoo!, or MSN, or if you load http://seophp.example.com/popup.phpdirectly from the address bar of your browser, the navigation link should appear (see Figure 6-2).

6.

Now is a great time to test the RefControl Firefox plugin mentioned in Chapter 2. This plugin allows you to display and modify REFERER information. Install the plugin and navigate to http://seophp.example.com/catalog.html. In the page, click the link that opens the popup window, and note the HTTP REFERER displayed in the status bar (see Figure 6-3). You can see that the catalog link doesn’t show up when the popup is opened as a result of naviga-tion from within your site.

Figure 6-2

Figure 6-3

That was quite a bit of code, but this is a useful technique! Once your popup library is in place, it becomes really easy to make the navigation link show up whenever it is needed. Here you use the simulated popup window method, but you could have also used a regular JavaScript popup with the same results.

In order to add the navigational link to any popup, there are only two steps you need to take. First, you need to include the popup_utils.inc.phpscript in your popup script. This is what you did in popup.php:

<?php

// load the popup utils library

require_once ‘include/popup_utils.inc.php’;

?>

Then, you need to call the display_popup_navigation()function that’s defined in popup_ -utils.inc.php, in the place where you want the navigational link included:

<?php

// display popup navigation only when visitor comes from a SERP display_popup_navigation();

?>

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 naviganaviga-tion link isdisplayed.

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_DOMAINconstant, 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_navis true, you display the navigation link:

// display navigation if necessary if ($disp_nav == true)

{

echo ‘<a href=”catalog.html”>Visit our catalog page!</a>’;

}

Dans le document Search Engine Optimization with PHP (Page 148-154)