header() strange behaviour

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
flycast
Forum Commoner
Posts: 37
Joined: Wed Jun 01, 2005 7:33 pm

header() strange behaviour

Post by flycast »

I am using header to redirect if certain cookies are not present. The code:

Code: Select all

function cookieCheck(){

//Check for robots and allow them to see the site
if (preg_match ( "/Google/", $_SERVER['HTTP_USER_AGENT'])){
	//It's a robot
	exit();
}

//Check for cookies first
if (!isset($_COOKIE['State']) and !isset($_SESSION['State'])){
	ini_set('session.use_trans_sid', true);
	$_SESSION['Page'] = $_SERVER['SCRIPT_NAME'];
	setcookie("Page", $_SERVER['SCRIPT_NAME'], time() + (60*60));
	header("Location: http://legacykc.janasnyder.com/entry?PHPSESSID=".session_id());
	exit();
}elseif (isset($_COOKIE['State'])){
	ini_set('session.use_trans_sid', false);
	$State = $_COOKIE['State'];
	setcookie("State", $State, time() + (60*60*24*365*2));
}
}//End of cookieCheck function
When the cookie is not present instead of redirecting to the page I get an Apache page that says:
Title: 200 OK
OK

The document has moved here.
Does anybody have experience with this? Why is Apache not going straight to my page?
Post Reply