Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Another Simple thing

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default Another Simple thing

    I'm trying to make another simple thing like the simple mailer but a simple page counter. I want the counter to write the number with the users ip address and computer information. I have this code but for some reason it has "Resource ID #3." I dont know where it's getting the Resource ID # from or the 3 the file was set to 0. This is my code thanks for any help you can offer here.


    PHP Code:
    <?php 
    $user 
    =  $_SERVER['REMOTE_ADDR'];
    $computer $_SERVER["HTTP_USER_AGENT"];
    $count "hit.txt";
    $value fopen($count"r+");
    $entervalue fread($value999999);
    $entervalue entervalue 1;
    fwrite($value$value);
    fclose($value);
    $hitsfile "log.txt";
    $gethits fopen($hitsfile"r+");
    $page $value ". " $user " " $computer "\n";
    echo 
    $page;
    fwrite($gethits$page);
    fclose($gethits);
    ?>

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    try changing this: fwrite($value, $value); to this:fwrite($value, $entervalue); and this:$page = $value . ". " . $user . " " . $computer . "\n"; to this:$page = $entervalue . ". " . $user . " " . $computer . "\n";
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. The Following User Says Thank You to Master_script_maker For This Useful Post:

    bluewalrus (01-19-2009)

  4. #3
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

  5. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Okay I got it working now but decided to try and make it work better again hah. So I added in an attempt to see if a user has been to the site before but now it thinks the user has been there every time. Thanks for any further help you can offer with this
    PHP Code:
    <?php 
    $user 
    =  $_SERVER['REMOTE_ADDR'];
    $computer $_SERVER["HTTP_USER_AGENT"];
    //To Change the date formate from MM/DD/YY HH:MM go here http://www.php.net/date
    $date date('m/j/y H:i');
    $count "hit.txt";
    $value2 fopen($count"r+");
    $entervalue fread($value2999999999);
    $entervalue $entervalue 1;
    fclose($value2);
    $value fopen($count"w+");
    fwrite($value$entervalue);
    fclose($value);
    $hitsfile "log.txt";
    $gethits fopen($hitsfile"a+");
    $check fread($gethits9999999999);
    $page $entervalue ". " $date " " $user " " $computer "\n";
    //REMOVE ALL OF THIS IF YOU DON'T CARE IF A USER HAS BEEN HERE MORE THAN ONCE IN A DAY... REMOVE THAT . " "  IF YOU WANT TO BE MORE SPECIFIC TO IF THEY HAVE EVER BEEN THERE.
    $beenhere str_replace($check""$date " " $user);
    if (
    $date " " $user === $beenhere) {
    $entervalue $entervalue 1;
    die (
    "You've been here today.");

    else {
    //REMOVE UNTIL HERE
    fwrite($gethits$page);
    fclose($gethits);
    }
    ?>

  6. #5
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    try:
    PHP Code:
    <?php  
    $user 
    =  $_SERVER['REMOTE_ADDR']; 
    $computer $_SERVER["HTTP_USER_AGENT"]; 
    //To Change the date formate from MM/DD/YY HH:MM go here http://www.php.net/date 
    $date date('m/j/y H:i'); 
    $count "hit.txt"
    $value2 fopen($count"r+"); 
    $entervalue fread($value2999999999); 
    $entervalue $entervalue 1
    fclose($value2); 
    $value fopen($count"w+"); 
    fwrite($value$entervalue); 
    fclose($value); 
    $hitsfile "log.txt"
    $gethits fopen($hitsfile"a+"); 
    $check fread($gethits9999999999); 
    $page $entervalue ". " $date " " $user " " $computer "\n"
    //REMOVE ALL OF THIS IF YOU DON'T CARE IF A USER HAS BEEN HERE MORE THAN ONCE IN A DAY... REMOVE THAT . " "  IF YOU WANT TO BE MORE SPECIFIC TO IF THEY HAVE EVER BEEN THERE. 
    $beenhere preg_match("/".$user."/"$check); 
    if (
    $beenhere) { 
    $entervalue $entervalue 1
    die (
    "You've been here today."); 
    }  
    else { 
    //REMOVE UNTIL HERE 
    fwrite($gethits$page); 
    fclose($gethits); 

    ?>
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  7. The Following User Says Thank You to Master_script_maker For This Useful Post:

    bluewalrus (01-19-2009)

  8. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Yup that did it thanks.

    If anyone comes here looking for this the whole code is below. I had to add in the rewriting to the text file the count for the if the user had been there before. So it is as follows.


    PHP Code:
    <?php  
    $user 
    =  $_SERVER['REMOTE_ADDR']; 
    $computer $_SERVER["HTTP_USER_AGENT"]; 
    //To Change the date formate from MM/DD/YY HH:MM go here http://www.php.net/date 
    $date date('m/j/y H:i'); 
    $count "hit.txt"
    $value2 fopen($count"r+"); 
    $entervalue fread($value2999999999); 
    $entervalue $entervalue 1
    fclose($value2); 
    $value fopen($count"w+"); 
    fwrite($value$entervalue); 
    fclose($value); 
    $hitsfile "log.txt"
    $gethits fopen($hitsfile"a+"); 
    $check fread($gethits9999999999); 
    $page $entervalue ". " $date " " $user " " $computer "\n"
    //REMOVE ALL OF THIS IF YOU DON'T CARE IF A USER HAS BEEN HERE MORE THAN ONCE IN A DAY... REMOVE THAT . " "  IF YOU WANT TO BE MORE SPECIFIC TO IF THEY HAVE EVER BEEN THERE. 
    $beenhere preg_match("/".$user."/"$check); 
    if (
    $beenhere) { 
    $entervalue $entervalue 1
    $value fopen($count"w+"); 
    fwrite($value$entervalue); 
    fclose($value); 
    die (
    "You've been here today."); 
    }  
    else { 
    //REMOVE UNTIL HERE 
    fwrite($gethits$page); 
    fclose($gethits); 

    ?>

  9. #7
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    glad i could help
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  10. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Nice how you can disable the IP addresses of people you don't like by putting them in your user-agent string and then accessing the page And that IP addresses that contain other IP addresses will be considered the same address (e.g. 123.123.123.123 and 3.123.123.1). Also note how the script tries to read from the hits file 999999990 bytes more than are ever likely to be used, how if two users access the page at the same time it's likely that only one will be recorded, how regular expressions are used for a simple substring match, and how instead of just checking whether the user has been there before updating the hit counter, the script always updates the hit counter but then goes back and decreases it again...

    Also, don't use locale-specific date formats in code, especially not the crazy American one — use ISO-8601 standard date format, DD-MM-YYYY (or 'N-m-Y').
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  11. The Following User Says Thank You to Twey For This Useful Post:

    bluewalrus (01-19-2009)

  12. #9
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Yea I was considering going back through and reverse it so that it checked first to see if the user had been there then functioned the idea for that came one I first got it working. What do you mean by disabling the ip addresses with the users-agent string?

    Also I noticed the checker I had isn't checking the date and user it's just checking the user so I just tried chaning to to this
    PHP Code:
    $beenhere preg_match("/".$date." ".$user."/"$check); 
    but I got this:
    Warning: preg_match(): Unknown modifier '1' in /hsphere/local/home/crazychr/bluewalrus.net/hitter/hit.php on line 19
    Is it because of the " "?

    Is there an infinite function so it will read the whole file no matter the size?

  13. #10
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    I've rewritten your code using the function file_get_contents() which retrieves the whole file.
    PHP Code:
    <?php  
    $user 
    =  $_SERVER['REMOTE_ADDR']; 
    $computer $_SERVER["HTTP_USER_AGENT"]; 
    $date date('N-m-Y'); 
    $counter "hit.txt"
    $cData file_get_contents($counter);

    $logfile "log.txt"
    $log file_get_contents($logfile);  
    $page $cData ". " $date " " $user " " $computer "\n"
    $beenhere str_replace($date." ".$user''$log); 
    if (
    $beenhere===$log) { 
        
    $cData $cData 1;
        
    file_put_contents($logfile$log.$page); 
        
    file_put_contents($counter$cData);
    } else { 
        
    file_put_contents($counter$cData);
        die (
    "You've been here today.");

    ?>
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

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
  •