PHP session ID

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
I should know this, but how do you echo a session id in PHP?
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
PHP:
<?PHP
//hopefully you've started your session....

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

?>
 

supajason

Member
Messages
288
Reaction score
2
Points
18
I think its:
PHP:
<?PHP
session_start();
$ses_id = session_id();
echo 'Session ID = ' . $sid;
session_destroy();
?>

Easy!!!
 

phpasks

New Member
Messages
145
Reaction score
0
Points
0
<?PHP
ob_start();
session_start
();
$ses_id = session_id();
echo
'Session ID = ' . $sid;
session_destroy();
?>

You can used it this way.
 

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
leafypiggy: sorry, doesn't work
supajason: neither does yours
phpasks: nor yours

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


phpbb.php:
PHP:
<?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:
<?php
include("includes.php");
//...
include("phpbb.php");
echo $res;
?>

includes.php:
PHP:
<?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.
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
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.
 
Top