Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Trouble setting a cookie
Dear all
I am trying to set cookies using different arguments, at the moment one works and the other doesn't. I have 'cookie 1' sitting at the document root 'htdocs' of apache 1.3. and 'cookie 2' in a file named 'yourdomain.com' in htdocs. I cannot figure why cookie 1
works and cookie 2 doesn't:
Cookie 1 part 1:Code: Select all
<?php
$Month = 2592000 + time();
//this adds 30 days to the current time
setcookie(AboutVisit, date("F jS - g:i a"), $Month);
?>Cookie 1 part 2:
Code: Select all
<?php
if(isset($_COOKIE['AboutVisit']))
{
$last = $_COOKIE['AboutVisit'];
echo "Welcome back! <br> You last visited on ". $last;
}
else
{
echo "Welcome to our site!";
}
?>----------------------
Cookie 2:
Code: Select all
<?php
setcookie("color", "black", time()+3600, "/", "yourdomain.com", 0);
?>
<html>
<head>
<title>cookie with if statement</title>
</head>
<body>
<?php
if (isset($_COOKIE[vegetable])) {
print "<p>Hello again, your chosen vegetable is $_COOKIE[vegetable]</p>";
} else {
print "<p>Hello you. This may be your first visit</p>";
}
?>
</body>
</html>From the code can anyone see why cookie 2 does not work or does anyone know of any tutorials that list multiple ways for setting, reading and manipulating with cookies?
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]