Jump to content

Archived

This topic is now archived and is closed to further replies.

Buyocat

Using session_name()

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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:
[code]function my_session_start($id, $name)
{
    session_id($id);
    session_name($name);
    session_start();
}[/code]
Then when you want to start your session do this:
[code]<?php
// get session function
include 'session.php';

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

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

Or create your own [url=http://uk2.php.net/manual/en/function.session-set-save-handler.php]session handler[/url]

Share this post


Link to post
Share on other sites

×

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.