php automatically does that for you.
1-on the first request, since php did not receive an sid from a cookie nor through the url, php will add the sid to the html for you, AND send a cookie.
2-on the next request, if php receives the cookie back, it stops adding the sid through the url. but if all it receives is the sid through the url, then it just keeps adding the sid to the query string.
but you could do something like this
$is_crawler = false;
$crawlers = array(
'google',
'msn',
'inktomi',
); // add more
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
foreach ($crawlers as $crawler) {
if (false !== strpos($ua, $crawler)) {
$is_crawler = true;
break;
}
}
if ($is_crawler) {
ini_set('session.use_trans_sid', 0);
}