Accessing Session Files
Posted: Sat Mar 15, 2008 9:36 pm
Ok first i'll explain what i am trying to do and then how much i have working. I have a php page that prints out the username of each session online (username session var created once the user logs in). Just like a page to show who is online by reading the sessions currently in the specified folder on the server and printing out one of the session variables stored in each file. This works fine........until i add session_start() to the top of the php page and then it doesn't work at all. Here is the code that accesses the folder the sessions are stored in and prints of one of the variables:
This works fine no problem but when i add session_start() to the top of the php file it echo's nothing to the screen. Can someone tell me why this is happening and help find a way around this problem? Thanks.
Code: Select all
$dir = "C:/xampp/tmp";
$files = scandir($dir);
$allSessions = "";
$c = false;
for($x = 0; $x != count($files); $x++){
$pos = strpos($files[$x],"sess_");
if($pos === false){}else{
$filehandle = fopen ('C:/xampp/tmp/'.$files[$x], 'r');
$sessiondata = fread ($filehandle, 4096);
fclose($filehandle);
session_decode($sessiondata);
$sessiondata = explode(";",$sessiondata);
$searchString = trim($sessiondata[0]);
$findMe = 'uname';
$pos = strpos($searchString, $findMe);
if($pos === false){}else{
$commaPos = strpos($searchString, '"');
$searchString = str_replace('"','',$searchString);
if(substr($searchString, ($commaPos))!=""){
echo "<a href='#'>".substr($searchString, ($commaPos))."</a>,";
}
}
}
}