Jump to content

remember user with cookies


jwk811

Recommended Posts

You can create a cookie with php using the [url=http://php.net/setcookie]setcookie[/url] function

Here is the basics of the function:
setcookie(name, value, expirey_time);

The name is the the name of your cookie, the value is what your cookie holds and the expire_time is when your cookie expires in seconds.

So if you want to create a remember me cookie then you'd set it using this:
[code]setcookie('remeberMe', $user_var, time()+3600*24*365[/code]

What that will do is create a cookie called rememberMe which holds the value of the $user_var variable and it will expire a year from now. To access the cookie you'll use the $_COOKIE superglobal variable. Example:

$_COOKIE['cookie_name_here']

So to access your remeberMe cookie you'd use $_COOKIE['remeberMe']

Note when you use the setcookie function make sure there is no output before you use this function, otherwise you may get a header already sent error message/blank screen.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.