Cookie redirect won't help. Any suggestions?
Posted: Thu Aug 11, 2005 8:43 am
Take a look at the code below. What it does is to check if a cookie called "resoRedirect" exists. If not, it will let the user set it (the cookie is being set I checked on my own.) Otherwise, it needs to redirect to a page according to the cookie content.
If the cookie exists, the page is not supposed to show anything, onlt redirect the user to the next page.
Everything works perfectly, except for when the page is loaded after the cookie has been set, it won't redirect me unless I refresh the page.
Maybe you know why?
If the cookie exists, the page is not supposed to show anything, onlt redirect the user to the next page.
Everything works perfectly, except for when the page is loaded after the cookie has been set, it won't redirect me unless I refresh the page.
Maybe you know why?
Code: Select all
<?php
if (!isset($_COOKIE['resoRedirect'])) {
$html1 = <<<EOT
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html>
<head>
<link rel='stylesheet' type='text/css' href='scripts/style.css'>
<title>.:: The Official Cry Havoc Website ::.</title>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>
EOT;
$html2 = <<<EOT
<SCRIPT LANGUAGE='JavaScript'>
function putCookie(RediReso)
{
document.cookie="resoRedirect"+"="+RediReso+"; expires=Monday, 04-Apr-2010 05:00:00 GMT";
}
</SCRIPT>
EOT;
$html3 = <<<EOT
</head>
<body style='background-image:url('images/int_bg.png');'>
<center>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<table background='images/int_frame_bg.png' width='260'>
<tr><td align='center'>
<br><br>
Please choose your resolution:<br />
<a href="index_800.html" onClick='putCookie(800)'>800x600</a>
<a href="index_1024.html" onClick='putCookie(1024)'>1024x768</a>
<a href="index_1280.html" onClick='putCookie(1280)'>1280x960+</a>
<br>
<br>
</td></tr>
</table>
</center>
</body>
</html>
EOT;
print $html1."<br>";
print $html2."<br>";
print $html3;
}
else {
function relativeRedirect($relative_url) {
if($relative_url{0} != DIRECTORY_SEPARATOR)
{
$relative_url = DIRECTORY_SEPARATOR.$relative_url;
}
if($_SERVER['HTTPS'] == 'on')
{
$http = 'https://';
}
else {$http = 'http://';}
header("Location: " . $http . $_SERVER['SERVER_NAME'] . dirname($_SERVER['PHP_SELF']) . $relative_url);
exit;
}
$redirect_file="index_".$_COOKIE['resoRedirect'].".html";
relativeRedirect($redirect_file);
}
?>