Create a cookie without using a form
Moderator: General Moderators
Create a cookie without using a form
Is there a way I can set a cookie by pressing a link and not by submitting a form?
I tried to do it but it didn't work.
I mean, the cookie is set, but I dont get redirected to the page.
Maybe you can help me out:
I mean, the cookie is set, but I dont get redirected to the page.
Maybe you can help me out:
Code: Select all
<?php
if (!isset($_COOKIE['Resolution'])) {
$html = <<<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">
<SCRIPT LANGUAGE="JavaScript">
cookie_name = "Resolution";
function putCookie(resosize) {
if(document.cookie != document.cookie)
{index = document.cookie.indexOf(cookie_name);}
else
{ index = -1;}
if (index == -1)
{
document.cookie=cookie_name+"="+resosize+"; expires=Monday, 04-Apr-2010 05:00:00 GMT";
}
}
</SCRIPT>
</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('800x600')">800x600</a>
<a href="index_1024.html" onClick="putCookie('1024x768')">1024x768</a>
<a href="index_1280.html" onClick="putCookie('1280x960')">1280x960+</a>
<br>
<br>
</td></tr>
</table>
</center>
</body>
</html>
EOT;
print $html;
}
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['Resolution']."html";
relativeRedirect($redirect_file);
}
?>
Last edited by pilau on Wed Aug 10, 2005 4:03 pm, edited 1 time in total.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
if(document.cookie != document.cookie)Well, I copied it out of this website, and didn't think of removing it...
The shame.
[EDIT]
Anyway, it works, I just found out the problem. Thanks.
[/EDIT]
[EDIT]
Wait! it's not working...
Waaaaa!
The cookie is not being created! Why on earth?
[/EDIT]
Here's the code:
The shame.
[EDIT]
Anyway, it works, I just found out the problem. Thanks.
[/EDIT]
[EDIT]
Wait! it's not working...
The cookie is not being created! Why on earth?
[/EDIT]
Here's the code:
Code: Select all
<?php
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;
}
if (!isset($_COOKIE['Resolution'])) {
$html = <<<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">
<SCRIPT LANGUAGE="JavaScript">
cookie_name = "Resolution";
function putCookie(resosize) {
document.cookie=cookie_name+"="+resosize+"; expires=Monday, 04-Apr-2010 05:00:00 GMT";
}
</SCRIPT>
</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('800x600')">800x600</a>
<a href="index_1024.html" onClick="putCookie('1024x768')">1024x768</a>
<a href="index_1280.html" onClick="putCookie('1280x960')">1280x960+</a>
<br>
<br>
</td></tr>
</table>
</center>
</body>
</html>
EOT;
print $html;
}
else {
$redirect_file="index_".$_COOKIE['Resolution'].".html";
relativeRedirect($redirect_file);
}
?>