Jump to content

[SOLVED] Sessions destroying when browser closes


9three

Recommended Posts

Hey,

 

I'm using sessions for a log in. What I'm noticing though is that when I close the browser, the session does not destroy it self. I want the log in page to appear again if the browser is closed for security purposes.

 

I'm just using a basic session nothing complex:

 

      $_SESSION['username'] = $username;
      $_SESSION['user_agent'] = 1;
      header('Location: index.php');

try using this:

 

setcookie("PHPSESSID",session_id(),null);

 

This will work as long as you are using cookies for the sessions (if u dont see phpsessid=f849fh49h8f084 in every URL on ur site then ur using cookies).

 

The cookie function when no argument is passed to the time part (null above), the cookie is usually destroyed upon browser exit.

 

Hope this helps;

 

EDIT: There is a php ini variable that is responsible for controlling the time a php session cookie remains intact. i believe: session.cookielifetime or similar.

By default, sessions use cookies to store the "Session Identifier Key", in a cookie called PHPSESSID.

 

IF you dont use sessions, you must pass the Session Identifier Via the URL, in the form of: http://www.web.com/index.php?phpsessid=a8b087ef087cb087a234

---

 

Cookies are as secure as form data, users can create.modify and delete cookies willingly, put whatever they want inside of them. As long as you properly "sanitise" the data coming from the cookie your script should be fine.

 

Hope this helps,

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.