user1801540
user1801540

Reputation:

Cookies won't set?

So, I'm making a simple website blocked script, and in the end it will just say website blocked, and will foreword someone to a page like igoogle, with weather, news, and such, but I can't create a cookie at all, in any script. I put the create cookie script in the same page as the read cookie script. What am I doing wrong?

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>***WEBSITE BLOCKED***</title>
</head>
<body>
<?php
$expire=3600;
echo $expire;
setcookie("user2112", "Justin Marmorato", $expire);
if (isset($_COOKIE["user2112"]))
echo "Welcome " . $_COOKIE["user2112"] . "!<br>";
else
echo "Welcome guest!<br>";
?>
</body>
</html>

Heres the output every time 3600Welcome guest!

Upvotes: 1

Views: 692

Answers (1)

Nijraj Gelani
Nijraj Gelani

Reputation: 22

I got it... You should set

$expire = time()+3600;

not

$expire = 3600;

OK... I tested it and it works...

Upvotes: 1

Related Questions