Page 1 of 1

Straiten me out with Sessions

Posted: Thu Aug 26, 2004 5:48 pm
by ast3r3x
Ok...I'm going crazy, and am thinking about redoing my session handling functions on the forum board I'm writing. I want to get a few things clear first...

If I want to have the session last for a month, I set $x to whatever many seconds a month is, and if it's 0, it's until the browser closes correct?

Code: Select all

session_set_cookie_params($x)
--------------------

If I want to have the session automatically start if the user is still within that month. I can do the following I hope.

Code: Select all

if(session_id() != FALSE)
{
	session_start(session_id());
}
--------------------

When someone logs out. How do I clear their session data. It seems when I try it, that it just starts again because it never really clears.

Code: Select all

session_destroy();
session_unset();
$_SESSION = array();
-------------------

Now the real problem I came to ask about is that on one page, $_SESSION['uid'] is the user name, but on the next page, when I don't even touch the session array, the 'uid' becomes an array and I have to call $_SESSION['uid'][0] to get it to work. What is up with this?!

-------------------

Any help, advice, useful information would be appreciated. I had it working so perfectly on my computer, but I moved servers and it all went to hell. I assume it's because I have my php.ini file set differently then their servers, so auto_start and the lifetime I had working for me on my computer.

Edit: Side note while I have your attention. For my forums...how do I keep track of how many times a page has been viewed?

Re: Straiten me out with Sessions

Posted: Thu Aug 26, 2004 7:53 pm
by Buddha443556
ast3r3x wrote:When someone logs out. How do I clear their session data. It seems when I try it, that it just starts again because it never really clears.

Code: Select all

session_unset();
session_destroy();
setcookie( session_name() ,"",0,"/"); // delete the cookie too.
Might want to delete the cookie too. Otherwise session_id() != FALSE may not work on the next page. PHP will pick up the session id from the cookie if you don't delete it. PHP will usually create an empty session with the id from the cookie. Makes it look like it was never destroyed. Which sound like what you maybe experiencing.