Jump to content


Photo

Using session_name()


  • Please log in to reply
2 replies to this topic

#1 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 23 July 2006 - 04:41 PM

I'm working on making my sessions customized and I've found something strange with the session_name function that I thought I'd ask the community about.  I wanted to see how things worked so I made two pages, on the first I start a session and assign it an ID and name using session_id and session_name.  On the second page I just print_r the $_REQUEST array to see how the sessions are being passed.  The problem is that when I do that I see that there are two sessions.  One which is PHPSESSID  the other is the name I set and both have the ID that I set.  Now I've checked to see that auto sessions are off -- they are -- so I'm a little confused as to why session_name is just making a duplicate and not replacing PHPSESSID.  Does anyone know why this is happening or a work around?
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#2 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 23 July 2006 - 05:53 PM

EDIT
Problem solved :)
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 23 July 2006 - 05:59 PM

When ever you define a custom session id or name for a session you will have define session_id and session_name before the use of session_start in order for PHP to load up your session. If you dont want to define session_id('11'); and session_name('test session'); every time you want to access the session, either create a function eg:
function my_session_start($id, $name)
{
    session_id($id);
    session_name($name);
    session_start();
}
Then when you want to start your session do this:
<?php
// get session function
include 'session.php';

// start session
my_session_start('11', 'test_sess');

// rest of code
That way you called three function with just one function.

Or create your own session handler




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users