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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.