View No of visitors online

A

Anonymous

Guest
Hello,

Is it possible to find out how many visitors are viewing my site using session’s functions?

Or I shall use some other functions of PHP

Thanks & Regards,
Vikas Garg
EnablingBiz Esolution
http://www.enablingbiz.com
 
Gesf, thanks for your answer!

Still I have a doubt. From where the functions open, close & other will be called. Did they would be called automatically or we have to call it.


Code:
<?php
function open($save_path, $session_name)
{
  global $sess_save_path, $sess_session_name;
      
  $sess_save_path = $save_path;
  $sess_session_name = $session_name;
  return(true);
}

function close()
{
  return(true);
}

function read($id)
{
  global $sess_save_path, $sess_session_name;

  $sess_file = "$sess_save_path/sess_$id";
  if ($fp = @fopen($sess_file, "r")) {
   $sess_data = fread($fp, filesize($sess_file));
   return($sess_data);
  } else {
   return(""); // Must return "" here.
  }

}

function write($id, $sess_data)
{
  global $sess_save_path, $sess_session_name;

  $sess_file = "$sess_save_path/sess_$id";
  if ($fp = @fopen($sess_file, "w")) {
   return(fwrite($fp, $sess_data));
  } else {
   return(false);
  }

}

function destroy($id)
{
  global $sess_save_path, $sess_session_name;
      
  $sess_file = "$sess_save_path/sess_$id";
  return(@unlink($sess_file));
}

/*********************************************
 * WARNING - You will need to implement some *
 * sort of garbage collection routine here.  *
 *********************************************/
function gc($maxlifetime)
{
  return true;
}

session_set_save_handler("open", "close", "read", "write", "destroy", "gc");

session_start();

// proceed to use sessions normally

?>

Vikas Garg
enablingbiz Esolution
 
Yep. Those functions will work/be called... let's say... automatically, everytime a session is open, closed, writen ...
 
Back
Top