Jump to content

Recommended Posts

Hi,

 

I currently have a fully working site that just uses sessions, but I'm looking to add cookies. I know how to add cookies and check for them; the problem is I can't think of the proper 'order' to do things.

 

What I *think* should happen is this:

[*]Users logs in. If the 'remember' box isn't checked, just create a new session and proceed as normal.

[*]If the 'remember' box isn't checked, set a cookie that lasts a month (or whatever) and then create a new session.

[*](This is where I'm struggling) If a user returns, check for the cookie and if they have one, just create another session and proceed as normal.

[*]Throughout the users visit to the site, only check for a SESSION variable, only check for a cookie on login.php

 

The trouble is that third point; isn't it easy to forge a cookie, and therefore to get easy access to the site? What should I put in the cookie, the username, the password? Should I create a number of cookies?

So, from looking at the docs, am I right in saying all I need to do is add a session_set_cookie_params function at the top of the first page the user logs in to?

 

I have a login page (call it login.php) a page to process the login which is called via AJAX (call it login-process.php) and then a page which is protected; the first page a user sees when they log in (index.php). I should add session_set_cookie_params at the top of index.php? How would I transfer the information to index.php from login_proc.php that the user wants to be remembered?

 

Sorry for the questions, I just had no idea this route existed so I can't grasp it fully at the moment (as an addition, I'm on a shared server, so would there be a problem in trying to extend PHP session lifetimes?)

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.