note 50625 added to ref.session

From: Date: Fri, 04 Mar 2005 23:41:43 +0000
Subject: note 50625 added to ref.session
Groups: php.notes 
Request: Send a blank email to php-notes+get-85954@lists.php.net to get a copy of this message
This is a simple code, to read all kind of session informations, for all php user in a UN*X Server. All php session information, are stored in tmp files: Ex: ls -1 /tmp/sess_* /tmp/sess_3a0c122ea49eab3a9cea37d426463945 /tmp/sess_63fe2dda925f836a454368ee8b157ba6 /tmp/sess_8649e55af46746c3f899cf316006e4b5 /tmp/sess_8ffa7e35e7c0be16a213e97602aba31e The code below, is a sugestion to count and identify users on-line: <? //Create a session variable, for user name (in logon page for example) $_SESSION["LogonUserVar"]="user.name"; ?> <? //Program to count and print logged users $files=f_ls(); foreach($files as $path){ if($fsize =filesize($path)){ $fp = fopen($path,'rb'); $lines.=fgets($fp,$fsize); fclose($fp); $fields = explode(";",$lines); $fsize =filesize($fullPath); foreach($fields as $field){ if(ereg("^LogonUserVar",$field)==true){ $aName=explode(":",$field); $name=str_replace('"','',$aName[2]); $aUser[$name]=$aUser[$name]+1; } } } } $c=0; $html1= "<html><body>".gtime()."<br>"; foreach($aUser as $user=>$nSessions){ $html3.= "<tr><td>".$user."</td><td>".$nSessions."</td></tr>"; $c++; } $html2="<br>$c users on-line:<br><br><table><td>User</td><td>nSessions</td>"; $html=$html1.$html2.$html3."</table></body>"; print $html; function f_ls(){ $command="ls -1 /tmp/sess_*"; if ($proc = popen("($command)2>&1","r")){ while (!feof($proc)) $contents .= fgets($proc, 1000); } pclose($proc); return explode("\n",$contents); } function gtime() { return date('d/m/Y H:i:s'); } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.session.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50625 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50625&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50625&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50625&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50625&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50625&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50625&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85954) next »