/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Setting php cookie due to form input

ok iv got a form, with a username and password input, i want to turn the username into a cookie, i found the script for this, but it doesnt seem to work. here it is:

[code=php]
<?php
if (!isset($_COOKIE[‘user’])) {
setcookie(“user”, $_POST[‘user’], time() + 3600);
}
?>
//and the form…
<html>
<body>

<form method=”post” action=”login.php” onsubmit=”return validate_form(this)”>
Username: <input name=”user” type=”text”><br />
Password: <input name=”password” type=”password”><br />
<input type=”submit” value=”Sign in”> <input type=”Reset”>
</form>
</body>
</html>
[/code]

Don’t worry about validation or anything like that, iv got it all sorted, i just need to turn it into a cookie.

Here is the page where i want to display the cookie, but this works when i set the cookie normally, so it should work

[code=php]
<html>
<body>
<?php
echo “Welcome ” . $_COOKIE[“user”] . “!<br />”;
?>
</body>
</html>
[/code]

thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordJun 11.2008 — Hmm looks right, maybe try this

[code=php]
// set as string in variable
$tmp_cookie_user = "" .$_POST['user'] ."";

if (!isset($_COOKIE['user'])) {
setcookie("user", $tmp_cookie_user, time() + 3600);
}
[/code]
Copy linkTweet thisAlerts:
@Dark_Light2authorJun 11.2008 — hi, yes i thought it looked right to, very confused, instead i resolved it by moving the setcookie into the login.php page, it now works. I havent tried your idea but i spect that would work aswel. Not sure why mine wasnt, but there we go. sorry if u spent along time on this!
×

Success!

Help @Dark_Light2 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.28,
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,
)...