+ Reply to Thread
Results 1 to 7 of 7

Thread: PHP session ID

  1. #1
    callumacrae's Avatar
    callumacrae is offline not alex mac callumacrae is just really nice
    Join Date
    Dec 2007
    Location
    Wellesbourne, England
    Posts
    5,162

    PHP session ID

    I should know this, but how do you echo a session id in PHP?
    I can customise your phpBB board. Send me a PM.
    lynxphp - info, tutorials and scripts
    "A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."

  2. #2
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: PHP session ID

    [php]
    <?PHP
    //hopefully you've started your session....

    echo "Session ID =. $_SESSION['sessionname'];

    ?>
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  3. #3
    supajason's Avatar
    supajason is offline x10 Lieutenant supajason is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    England........:-)
    Posts
    288

    Re: PHP session ID

    I think its:
    PHP Code:
    <?PHP
    session_start
    ();
    $ses_id session_id();
    echo 
    'Session ID = ' $sid;
    session_destroy();
    ?>
    Easy!!!
    supajason was here

  4. #4
    phpasks is offline x10 Sophmore phpasks is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    145

    Re: PHP session ID

    <?PHP
    ob_start();
    session_start
    ();
    $ses_id = session_id();
    echo
    'Session ID = ' . $sid;
    session_destroy();
    ?>

    You can used it this way.
    Asif Khalyani
    http://www.phpasks.com

  5. #5
    callumacrae's Avatar
    callumacrae is offline not alex mac callumacrae is just really nice
    Join Date
    Dec 2007
    Location
    Wellesbourne, England
    Posts
    5,162

    Re: PHP session ID

    leafypiggy: sorry, doesn't work
    supajason: neither does yours
    phpasks: nor yours

    I think it must be me, not you...


    phpbb.php:
    PHP Code:
    <?php
    define
    ('IN_PHPBB'true);
    $phpbb_root_path "forum/";
    $phpEx substr(strrchr(__FILE__'.'), 1);
    include(
    $phpbb_root_path 'common.' $phpEx);
    include(
    $phpbb_root_path 'includes/functions_display.' $phpEx);

    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup('');

    $username request_var('username''');
    $count request_var('count'0);
    $submit request_var('submit''');
    $done false;

    if(
    $user->data['is_registered'])
    {
    $ses_id session_id();
    $res "<a href=\"" $phpbb_root_path "ucp.php?mode=logout&sid=" $sid "\">Logout [" $user->data['username'] . "]</a>";
    }
    else
    {
    $res "<a href=\"" $phpbb_root_path "ucp.php?mode=login\">Login</a>";
    }
    ?>
    index.php:
    PHP Code:
    <?php
    include("includes.php");
    //...
    include("phpbb.php");
    echo 
    $res;
    ?>
    includes.php:
    PHP Code:
    <?php
    //security code - removed
    session_start();
    function 
    startPige()
    {
    echo 
    "<html><head><title>The Paper Hub</title></head><body>
    //..."
    ;
    }
    function 
    endPige()
    {
    echo 
    "//...
    </body></html>"
    ;
    }
    ?>
    I've removed quite a lot of unwanted code.
    I can customise your phpBB board. Send me a PM.
    lynxphp - info, tutorials and scripts
    "A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."

  6. #6
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: PHP session ID

    check this out:

    http://us.php.net/manual/en/function.session-id.php

    you have to set the session ID or session_id() returns ""
    Edit:
    also make sure you set the session id before starting a session
    Last edited by garrettroyce; 07-10-2008 at 12:45 PM. Reason: Automerged Doublepost

  7. #7
    woiwky is offline x10 Lieutenant woiwky is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    390

    Re: PHP session ID

    Quote Originally Posted by Alex Mac View Post
    leafypiggy: sorry, doesn't work
    supajason: neither does yours
    phpasks: nor yours

    I think it must be me, not you...
    Actually, it isn't you. supajason's code is fine, except that he used $ses_id to store the id but then used $sid in the echo. So just change $sid to $ses_id or vice versa and it should work fine.
    "But you have access to the greatest source of knowledge in the universe."
    "Well I do talk to myself sometimes, yes."

    "I'm back, and I'm bad! Obviously within certain, sensible, preset parameters"

+ Reply to Thread

Similar Threads

  1. Replies: 3
    Last Post: 03-10-2008, 12:22 PM
  2. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  3. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers