/    Sign up×
Community /Pin to ProfileBookmark

php cookies help needed

I’m trying to learn how to make cookies, so i made 3 files: [URL=http://projep.t35.com/phptests/cookie.html]cookie.html[/URL]
which has a form with the action to go to cookie.php :

[code=php]<?
$name = POST[‘name’];
setcookie(“username”, $name, time()+9999);
?>
<html>
<head>
<title>Cookie set</title>
</head>
<body>
<?
echo ‘The cookie has been set. Click a link on the page to navigate the site.’;
?>
</body>
</html> [/code]

and then id change the url to go to cookie2.php:

[code=php]<?php
if (isset($_COOKIE[“username”]))
echo “Welcome ” . $_COOKIE[“username”] . “!<br />”;
else
echo “You are not logged in!<br />”;
?>[/code]

however, it doesn’t work at all. what’d i do wrong?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@YoNFeb 16.2004 — According to your form you are using the get method.. Try this:[code=php]$name = $_GET['user']; // Instead of $name = POST['name'];[/code]
Copy linkTweet thisAlerts:
@Ben_RogersauthorFeb 16.2004 — Nevermind, I fixed it myself. I just started over, and now it works. [URL=http://projep.t35.com/nme.php]see for yourself[/URL]
×

Success!

Help @Ben_Rogers spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...