note 50625 deleted from ref.session by betz
| From: | betz@php.net | Date: | Mon, 25 Jul 2005 09:13:20 +0000 |
| Subject: | note 50625 deleted from ref.session by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-92404@lists.php.net to get a copy of this message | ||
Note Submitter: helvecio_oliveira at yahoo dot com dot br
----
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');
}
?>