Results 1 to 2 of 2

Thread: PHP - Info to and from a file?

  1. #1
    Cheeko
    Guest

    PHP - Info to and from a file?

    Ok, What I am aiming to do is this...

    Create a php script that tells you how many people are or have viewed a script in the last 10 minutes by adding them to a file with a timestamp.

    I'll call them:

    online.php (The actual script)
    users.php (The script that contains who is online and when)

    So, I'm figuring, if everytime my script is called, it needs to do this:

    1) Check users.php, checkwhat users havent been on here for 10 minutes, then delete that line.

    2) Check if the user calling the script is online... if they arent, add them to the users.php, else ignore them.

    3) Produce a list of users left in the table.

    So, here's some other info about it:

    I have cookies, and the script will be called with the following variables already in use:

    $memnum (Member Number on my site)
    $user (Username on my site)
    $ip (Well, their IP)

    This users.php file will look like:

    $memnum&$user&$ip&time()

    e.g:

    00000001&Cheeko&13.46.98.132&992949731
    00000003&Dave&13.46.98.132&992949791
    00000007&Jimmy&13.46.98.132&992949799

    Here is what I need:

    How would I open users.php, get the memnum, time etc... into vars, check them anfd then delete them?

    should i do it like:

    $file = "users.php";
    list($old_memnum,$old_user,$old_ip,$old_time) = explode('&', $file[0]); ?
    But how would it know when there were no more users?
    How would I differentiate between users?

    Completely clueless, anyone who can help muchly appereciated!

    btw - I dont have MySQL

  2. #2
    Cheeko
    Guest
    Ok, been a change, I kinda got it sorted, need some help tho...

    Code:
    $file = file("/home/totalhos/public_html/dammit/interactive/users.fil");
    while ($i != 0) {  $x = $i - 1;
    list($oldmn,$olduser,$oldip,$timestamp) = explode('&', $file[$x]);
    if ($oldip == $ip) {
        $new = "N";
      } else {    $new = "Y";  
    }
    
    $td = $timestamp - time();  
    if (td > 600) {    // Delete $file[$x] HOW?!  
      $oc = $i - 1;
      } else {     
      $who[$p] = $olduser;    // Cos olduser is online still, right?
      $p++;
      }  $i = $i - 1;
    }
    $fp = fopen ("/home/totalhos/public_html/dammit/interactive/on_count.php", "w");
    fwrite($fp,'<? \r\n' . "$oc" . '\r\n ?>'); fclose ($fp);
    Ok, thats some code I have so far...

    You see the bit that says:

    // Delete $file[$x] HOW?!

    HOW would I delete that line? And i needs to be deleted aswell, not just replace by an empty string. Say the file was like this@

    matthew
    howard
    boyle

    and I wanted it to say:

    matthew
    boyle

    How would I remove that second line? or $file[1] ?

    Also, a few other questions...

    $who[$p] = $olduser;

    That line is correct right? I can assign an array like that? It doesnt need dimensioning first like VB?

    fwrite($fp,'<? \r\n' . "$oc" . '\r\n ?>');

    That would write:
    <?
    2
    ?>
    If $oc was equal to 2?

    Thanks for any help in advance.

    Cheers

Posting Permissions

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



Click Here to Expand Forum to Full Width