SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Set session id

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    spain
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Set session id

    What is the function to set/force new session id
    in native php session handling??

    thanks
    BillyJoe

  2. #2
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use session_start(), it creates a session or resumes the current one based on the current session id that's being passed through cookies, GET or POST.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    spain
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face I'm not newbie

    I already know that (I have some experience in sessions).

    I want to use PHP native session API, I need to force an ID when my code think its necesary.

    It must exist a function to set session ID I want ??!!??
    If not I will just make my own session API, It's easier for me, but code will obscure a bit (for other people).


    session_start();
    if ( !defined($_SESSION['user_id']) ){
    set_sid('725575&');
    }
    ...
    ...

  4. #4
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Can't you just destroy the session and make a new one?
    Mike
    It's not who I am underneath, but what I do that defines me.

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    spain
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No.

    if arive with this session: 2a2e58c3aaf16dcfde677c881954d824

    and do:
    session_start();
    session_destroy();

    Session 'file, dbrecord, ...' will be deleted, but now if I need to start another session at the same time, and do:
    session_start();
    session_destroy();
    session_start();

    It will create again a session with ID:
    2a2e58c3aaf16dcfde677c881954d824
    (couse $_GET['sid'] == '2a2e58c3aaf16dcfde677c881954d824')

    I don't want that, I want to start new session with other ID.
    ...
    session_start();
    set_sid(''2a2e58c3aaf16dcfde677c881954d111');
    ...



    PHP native sessions API also track sessions set by user, see(http://www.sitepointforums.com/showt...hreadid=102297).

    thanks for replies
    BillyJoe

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    spain
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    ...I just found the way to do it.

    session_start();
    ...
    session_close();
    $sid = my_generate_sid();
    session_id($sid);
    session_start();
    ...

    (for example ;p)

    Thanks to all.
    Last edited by BillyJoe; Mar 31, 2003 at 02:23.

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    spain
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now anothr problem

    with enable_trans_sid (to propagate sid)

    PHP Code:

    session_start
    ();
    session_destroy();
    session_start();
    session_destroy();
    session_id('1234');
    session_start();
    echo 
    'SID : '.SID;
    echo 
    '<br>session_id() : '.session_id(); 
    echo 
    '<br><textarea><a href="/script.php">script</a></textarea>';

    //... 
    if arrive this script with url ...?sid=qqqq
    you get:

    SID : sid=1234
    session_id() : 1234
    <a href="/script.php?sid=qqqq&sid=qqqq&sid=1234">script</a>


    !!!!!!!
    sid added 3 times to url!!!!.
    Anyone know why parser do this?
    Last edited by BillyJoe; Mar 31, 2003 at 02:47.

  8. #8
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    spain
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1234 will overwrite qqqq value,, (in next query/click)
    so... no matter,
    but it's a bit ugly :| isn't it?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •