try with session_id()
session_start();
echo $ses_id = session_id();
For more :- http://php.net/manual/en/function.session-id.php
Question
I'm trying to build a small stats analytic for website, so I created a table in database:
| ID | SESSION_ID | DATE_TIME | BROWSER | REFERER | ADDR_IP | FIRST_PAGE | LAST_ACTIVITY
And used this PHP code:
if (!isset($_SESSION)) {
session_start();
}
function curPageURL() {
//// function code
}
function getIpAddr() {
/// function code
}
function getBrowser() {
/// function code
}
if(!isset($_SESSION['org_referer'])) {
if(empty($_SERVER['HTTP_REFERER'])) {
$_SESSION['org_referer'] = "(direct) / (none)";
} else {
$_SESSION['org_referer'] = $_SERVER['HTTP_REFERER'];
}
}
if(!isset($_SESSION['first_page'])) {
$_SESSION['first_page'] = curPageURL();
}
$SESSION_ID = ?
$BROWSER = getBrowser();
$REFERER = $_SESSION['org_referer'];
$ADDR_IP = getIpAddr();;
$FIRST_PAGE = $_SESSION['first_page'];
$LAST_ACTIVITY = time();
How can I get the current session_id
?
Is the session_id
unique ?
I want to update rows with this query:
`UPDATE row FROM table WHERE SESSION_ID=$SESSION_ID`
Is this possible ?
Solution
try with session_id()
session_start();
echo $ses_id = session_id();
For more :- http://php.net/manual/en/function.session-id.php
OTHER TIPS
You can get the current session id with session_id()