SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How a counter of users ? such as ---> (231 Viewing)

    I want to count how many users are actually viewing the page, How is that possible?
    Thank you guys!

  2. #2
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It displays how many users requiestd this page in past few minutes.
    Simpliest way to do it is write down IP address and time of request.
    something like
    PHP Code:
    $data=file_get_contents("counter.dat");
    $counter=unserialize($data);
    $counter[$_SERVER['REMOTE_ADDR']]=time();
    foreach (
    $counter as $key = > $value) if ($value < (time()-180)) unset $counter($k);
    $data=serialize($counter);
    file_put_contents("counter.dat"$data);

    echo 
    count($counter)." viewing"
    it is just raw example. not a real code. locks must be taken inaccount.

  3. #3
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now There is a parse error some where in the line below.

    Parse error: parse error, expecting `')'' in
    Code where the parse error is
    Code:
     $data=file_get_contents("counter.dat");$counter=unserialize($data);$counter[$_SERVER['REMOTE_ADDR']]=time();foreach ($counter as $key = >

    Do I have to download the counter.dat file before using the code?

  4. #4
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes my bad. There is mistake.
    But if you don't know PHP syntax, this code isn't for you. It is just example, shows the way. Not a real code to put into site.

  5. #5
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have found this script php counter, but it is displaying a parse error on line 77 see the commented 77 line. My limited eyes doesn't notice any parse error can you see any?

    Thank you..

    PHP Code:
    <?php  
     session_start
    (); 

    /* Define how long the maximum amount of time the session can be inactive. */ 
    define("MAX_IDLE_TIME"3); 

    function 
    getOnlineUsers(){ 

    if ( 
    $directory_handle opendirsession_save_path() ) ) { 
    $count 0
    while ( 
    false !== ( $file readdir$directory_handle ) ) ) { 
    if(
    $file != '.' && $file != '..'){ 
    // Comment the 'if(...){' and '}' lines if you get a significant amount of traffic 
    if(time()- fileatime(session_save_path() . '\\' $file) < MAX_IDLE_TIME 60) { 
    $count++; 


    closedir($directory_handle); 

    return 
    $count


    else { 
    // line 77 where the parse error is
    return false




    echo 
    'Number of online users: ' getOnlineUsers() . '<br />'?>

  6. #6
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank to Alex help me find the parse error.

    i counted the brakets twice and i thought there were perfect but yes i missed the first if statment.

    Thank you..

    PS: Two eyes can see better than one..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •