0

I have a section of a website that sets a session variable. On another section of the site, if that variable is set, then it redirects them back to where the part of the site that set the variable.

<?php
//page1:
session_start();
$_SESSION['pg1']=true;

//page2
if ($_SESSION['pg1']===true)
  {
    header('Location: http://www.mysite.com/?page=1&WELCOME_BACK');
  }
?>

I think this behaves like I want by defalut, but I want Googlebot to be able to visit page1, then visit page2 without being re-directed. Can anyone confirm that? What I mean is, does a visit from Googlebot (or other SEs in general) generate a session that persists between pageviews.

(I know, if someone closes their browser they can come back to page2, but it's okay if they do that.)

TecBrat
  • 3,643
  • 3
  • 28
  • 45

2 Answers2

1
if ($_SESSION['pg1'] == true && strpos($_SERVER['HTTP_USER_AGENT'],'Googlebot') === false)
{

}

List of user agent strings: http://www.useragentstring.com/pages/useragentstring.php

Zul
  • 3,627
  • 3
  • 21
  • 35
  • +1 (I had already considered this) I'd actually need an array of SE useragents like Googlebot, Slurp, MSNBot... – TecBrat Feb 17 '12 at 18:00
  • No, this upvoted answer answers the question you linked, but not the question I asked. I upvoted it because it was a decent solution if my first choice didn't do what I wanted. – TecBrat Feb 17 '12 at 18:24
1

Googlebot does not accept cookies from strangers, so there will be no session variables when it visits your second page. This will result in what you want to happen here, but keep it also in mind for future reference.

Jon
  • 428,835
  • 81
  • 738
  • 806