So I figured how to grab session data at the very basic level; the session id is stored in a cookie named DokuWiki
, so this code gives me access to the data:
<?php
$dokuSessId = $_COOKIE["DokuWiki"] ?? null;
if ($dokuSessId !== null) {
session_id($dokuSessId);
}
session_start();
echo '<pre>';
var_dump($dokuSessId);
echo PHP_EOL;
var_dump($_SESSION);
Here is the output, so I can see if the $_SESSION variables contain data indicating a logged in user, like
string(26) "7befmqqpp88g45518nldnr276a"
and
array(11) {
["DW7fa065a06cb74b536c124cfbe56ac6d3"]=>
array(2) {
["auth"]=>
array(5) {
["buid"]=>
string(64) "1ecadee30d97a11003cUIUIUIUIUIUIUIeafdf9655a04abbUIUIUIUIUI9727fc71"
["time"]=>
int(1711790695)
["user"]=>
string(16) "dgvirtual_mmmm.lt"
["pass"]=>
string(40) "99106767676767674a59fbd7b1eb"
["info"]=>
array(4) {
["pass"]=>
string(60) "$2y$10$MD787878787878787878kbvqtS0QTCA86uJm"
["name"]=>
string(16) "User Name"
["mail"]=>
string(16) "dgvirtual@mmmm.lt"
["grps"]=>
array(3) {
[0]=>
string(5) "admin"
[1]=>
string(4) "user"
[2]=>
string(6) "tbztpg"
}
}
}
["bc"]=>
array(1) {
["start"]=>
string(7) "Sveiki!"
}
}
["dwfck_id"]=>
string(26) "7befmqqpp88g45518nldnr276a"
["dwfck_acl"]=>
int(255)
["dwfck_openfb"]=>
string(1) "y"
["dwfck_grps"]=>
array(3) {
[0]=>
string(5) "admin"
[1]=>
string(4) "user"
[2]=>
string(6) "tbztpg"
}
["dwfck_client"]=>
string(16) "dgvirtual_mmmm.lt"
["dwfck_sepchar"]=>
string(1) "_"
["dwfck_conf"]=>
array(4) {
["sepchar"]=>
string(1) "_"
["isadmin"]=>
bool(true)
["deaccent"]=>
string(1) "2"
["useslash"]=>
int(0)
}
["dwfck_ns"]=>
string(0) ""
["dwfck_top"]=>
string(0) ""
["dwfck_del"]=>
int(0)
}
and then, to access individual values I need, I can use something like this:
// Iterate over $_SESSION to find the nested array
foreach ($_SESSION as $key => $value) {
// Check if the value is an array and contains the keys you're interested in
if (is_array($value) && isset($value['auth']['info']['name'])) {
// Access the desired data
$name = $value['auth']['info']['name'];
$email = $value['auth']['info']['mail'];
$groups = $value['auth']['info']['grps'];
echo'<br>' . PHP_EOL;
// Output or use the retrieved data
echo "Name: $name\n";
echo "Email: $email\n";
echo "Groups: " . implode(', ', $groups) . "\n";
// Stop iterating once the desired data is found
break;
}
So I figured it out how to do that in the most primitive way. But any improvements would still be appreciated.