note 28534 deleted from ref.session by sniper
| From: | sniper@php.net | Date: | Tue, 21 Jan 2003 03:11:05 +0000 |
| Subject: | note 28534 deleted from ref.session by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-42462@lists.php.net to get a copy of this message | ||
If you automatically start sessions on every page, note that Google (amongst others) will probably
NOT spider your site, as it refuses to spider pages with sessions ids in the URL. Even if you use
cookies for the session, the googlebot will not accept the cookies, and so PHP will automatically
switch to the query string for persisting the session id.
To get around this, declare a global function:
function is_spider()
{
static $is_spider;
if (! isset($is_spider))
{
$spider_footprint = array('ooglebot', 'rawler', 'pider',
'obot', 'eek',
'canner', 'lurp', 'cooter',
'rachnoidea', 'KIT',
'ulliver', 'arvest');
$agent = getenv('HTTP_USER_AGENT');
$is_spider = 0;
// Is it a spider?
foreach($spider_footprint as $spider_name)
{
if (strstr($agent, $spider_name))
{
$is_spider = 1;
break;
}
}
}
return $is_spider;
}
and update your code so that this function is wrapped around every call to session_start(),
session_register, or $_SESSION variable setting, i.e.
if (! is_spider())
{
session_start();
}
// etc...
if (! is_spider())
{
$_SESSION['remember_me'] = TRUE;
}
The googlebot will then be able to traverse your site without having the session id block it's
way. Note that this is NOT cloaking, as it is not changing the content of the site, only the
'style' (i.e. it's similar to serving a CSS file based on whether the agent is
Netscape or Explorer).