/    Sign up×
Community /Pin to ProfileBookmark

setting cookies and using them as $

so im a noob in php…im trying to make a website that asks for name and then dependable on answer writes statement if else…it consist of two webpages:

webpage #1:

[code=html]<html>
<head>
<title>What is your name ?</title>
</head>
<body>
<form method=”post” action=”auth.php”>
<input class=”dane” type=”text” value=”” name=”user” maxlength=”18″ style=”width: 190px” />
<input class=”Button” type=”submit” value=”&#160;Submit&#160;” name=”submit” />
</form>
</body>
</html>[/code]

webpage #2:

[code=php]<?php
$iu_cookie_n = “user”;
$iu_cookie_v = $_POST[“user”];
$iu_cookie_e = “0”;
$iu_cookie_d = “”;
setcookie($iu_cookie_n, $iu_cookie_v, $iu_cookie_e, “/”, $iu_cookie_d, 0);

if ($_COOKIE[“user”] == Lukasz) {
echo “Witaj w systemie {$_COOKIE[“user”]}”;
}
else {
echo “Nie znam Cie!”;
?>[/code]

well when i try to run it no matter of my input, it says:

“Parse error: parse error, unexpected $ in /home/pvtdd/www/auth.php on line 13”

I bet i made mistake in setting variables…but where ?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 15.2006 — Unless there's other code you're not showing, here are a couple things I see:
<i>
</i>&lt;?php
$iu_cookie_n = "user";
$iu_cookie_v = $_POST["user"];
$iu_cookie_e = "0";
$iu_cookie_d = "";
setcookie($iu_cookie_n, $iu_cookie_v, $iu_cookie_e, "/", $iu_cookie_d, 0);
// Assuming "Lukasz" is not a defined constant, it should be quoted:
if ($_COOKIE["user"] == [color=red]"[/color]Lukasz[color=red]"[/color]) {
echo "Witaj w systemie {$_COOKIE["user"]}";
}
else {
echo "Nie znam Cie!";
[color=red]}[/color] // &lt;-- need closing brace
?&gt;
Copy linkTweet thisAlerts:
@JS7authorJun 15.2006 — thx, uhm now im trying to upgrade it a lil bit and make it a switch statement right

[code=php]<?php
$iu_cookie_n = "user";
$iu_cookie_v = $_POST["user"];
$iu_cookie_e = "0";
$iu_cookie_d = "";
setcookie($iu_cookie_n, $iu_cookie_v, $iu_cookie_e, "/", $iu_cookie_d, 0);

switch ($_COOKIE["user"]) {
break;
case "Tomasz":
case "Tomek":
case "tomasz":
case "tomek":
echo "Dobra robota {$_COOKIE["user"]}";
break;
case "Lukasz":
case "lukasz":
case "luke":
case "Luke":
echo "Witaj {$_COOKIE["user"]}";
break;
case "Gerardo":
case "gerardo":
echo "Arsenal Sucks ! And you are gay {$_COOKIE["user"]}";
break;
case "Eduardo":
case "eduardo":
case "eddy":
case "Eddy":
case "lalo":
case "Lalo":
echo "You are good in GHL {$_COOKIE["user"]}";
break;
default:
echo "I do not know who you are ! Get away !";
}
?>[/code]


and it works but each time i have to submit it twice...meanin i gotta go submit it then hit backspace to go back one page and submit same name again for it to work propertly, any ideas anyone ?
Copy linkTweet thisAlerts:
@NogDogJun 15.2006 — The page that sets a cookie cannot immediately read it - the cookie is not available until the next access of your site by that browser. But at this point you don't need to access the cookie, since your $_POST array already has the value you need, so you could just use $_POST['user'] throughout your switch block instead of $_COOKIE['user'].
×

Success!

Help @JS7 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...