note 28534 added to ref.session

From: Date: Thu, 16 Jan 2003 11:16:38 +0000
Subject: note 28534 added to ref.session
Groups: php.notes 
Request: Send a blank email to php-notes+get-42208@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). -- http://www.php.net/manual/en/ref.session.php http://master.php.net/manage/user-notes.php?action=edit+28534 http://master.php.net/manage/user-notes.php?action=delete+28534 http://master.php.net/manage/user-notes.php?action=reject+28534

« previous php.notes (#42208) next »