/    Sign up×
Community /Pin to ProfileBookmark

SetCookie Issue

Hi,

I am trying to set a cooking using the PHP setcookie function’

header (“Set-Cookie: UserAuth=2; path=/”);

The way this function works is .. if the user is correctly authenticated, it sets a cookie and sends the user to the member page.

If i use
header (“Set-Cookie: UserAuth=2; path=/”);

followed by

header (“Location: abc.php”);

then the cookie is deleted. If i just leave it at the first header (for testing) then the cookie stays. Not sure what is happening here.

Any help appreciated.

Neel

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordOct 15.2008 — Well I would not use a Cookie to authenticate access, Cookies can be forged.

I would look into Sessions.

if you need some code to play around with here is a good Site with login and Admin features.

Also posting any errors you might be getting would be helpful as well.
Copy linkTweet thisAlerts:
@swapdudeauthorOct 15.2008 — I use sessions but this is not at all secure data and ''they want to implement "Remeber Me" thing for the login ..

That is why i figured cookies is the best thing ..

Neel
Copy linkTweet thisAlerts:
@Phill_PaffordOct 16.2008 — Look at the link I gave you in the first post, this has some great code for "Remember Me" option.
Copy linkTweet thisAlerts:
@ariellOct 17.2008 — Phill is right, the code he mentioned is almost self-explaining.

As for your problem: In your example above mentioned, you overwrite the cookie-set in the header's command. This is why the cookie disappears.

An as for sessions, those will set a cookie anyway on the client's machine (unless you take measures to avoid this, which you obviously did not.) THIS (already initiated) cookie is a perfect base to use for individual information.

However, stick with those examples from Phil and you should be down the way.

Best from the south.
×

Success!

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