Jump to content

Using session_name()


Buyocat

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?
Link to comment
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]
Link to comment
Share on other sites

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.