PDA

View Full Version : Secure Cookies?



Hitman
25-11-2007, 03:07 PM
Hm, would doing a sort of cms feature be better with cookies then sessions?

And are there secure cookies, I've seen many unsecure ways...

Can somebody post info on how to make, delete and see if a cookie is present. Like, there's a page 'members only'. The members will have the cookie, if they have it they can view the page, if they don't they will receive an error message. How are they secure aswell...?

+REP to decent answers.

MrCraig
25-11-2007, 03:48 PM
Set cookie


ob_start();
setcookie("CookieName","Value (Username or something)",time()+3600);


Display Cookie


ob_start();
echo($_COOKIE["CookieName"]);


Members Only page


ob_start();
if(!isset($_COOKIE["CookieName"]))
die("Members Only access!");


Unset Cookie


ob_start();
setcookie("CookieName","",time()-3600);

Hitman
26-11-2007, 09:31 PM
I've got sessions working now, less code and much better IMO! :D

Beau
27-11-2007, 05:14 AM
Yeah, use sessions. Much more secure than cookies.

RichardKnox
27-11-2007, 07:09 PM
Encode the cookies using base_64?

Hitman
27-11-2007, 07:33 PM
Encode the cookies using base_64?It's easier to use sessions I'd say, they're clear and are secure. :D

Want to hide these adverts? Register an account for free!