Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Another Simple thing

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

    Default

    oo that does look a lot more efficient thanks, but i'm getting this error message when I try it.

    Fatal error: Call to undefined function: file_put_contents() in /hsphere/local/home/crazychr/bluewalrus.net/hitter/hit.php on line 14

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

    Default

    That means that you're still running PHP4. PHP5 has been out for five years now: upgrade, tell your host to upgrade, or else switch hosts.

    In the meantime, here's a replacement (but it only supports the first two arguments):
    Code:
    if (!function_exists('file_put_contents')) {
      function file_put_contents($fn, $data) {
        $f = fopen($fn, 'w');
        fwrite($f, $data);
        fclose($f);
      }
    }
    However, note that this doesn't help much against most of the problems there (and will still cause the script to break if the log file gets particularly big). For something like this you really want to use perhaps a small SQLite database.
    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!

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

    Default

    Okay I have it working now but a terrible way and with the date formatting even sloppier than before. I can't switch to php 5 because my server will make me cancel my other accounts and resign up. They said to could take 2 weeks to do this. So I'm trying it my moderately? poorly coded way.
    This works
    PHP Code:
    $date1 date('Hi'); 
    $date2 date('mjy'); 
    This brings up
    Warning: preg_match(): Unknown modifier 'j' in /hsphere/local/home/crazychr/bluewalrus.net/hitter/hit.php on line 20
    PHP Code:
    date1 date('H\:i'); 
    $date2 date('m\/j\/y'); 
    And this bring up this
    Warning: preg_match(): Unknown modifier '2' in /hsphere/local/home/crazychr/bluewalrus.net/hitter/hit.php on line 20
    PHP Code:
    $date1 date('H/:i'); 
    $date2 date('m\/j\/y'); 
    I was thinking I needed to clear out the : and / so I tried those other two ways but with no luck. I didn't change the code to the formatting you suggested twey because I and the users of this only use the crazy american date formating and for the first 12 days of the month it could be confusing to look at.

    The whole code as I have it working....

    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 
    $date1 date('Hi'); 
    $date2 date('mjy'); 
    $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 ". " $date1 $date2 " " $user " " $computer "\n"
    //REMOVE ALL OF THIS IF YOU DON'T CARE IF A USER HAS BEEN HERE MORE THAN ONCE IN A DAY.  IF YOU WANT TO BE MORE SPECIFIC TO IF THEY HAVE EVER BEEN THERE.  REMOVE "$date . " " ." If you
    $beenhere preg_match("/".$date2."/"$check);
    $beenhere2 preg_match("/".$user."/"$check);
    if (
    $beenhere) { 
    if (
    $beenhere2) {
    $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); 

    ?>
    Thanks for anymore help you can offer.

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

    Default

    Okay I'm trying to redo it again and I think this new way is more efficient except for the text file size problem anyway. Thanks for any more help you can offer here. I tried making the viewer check if the visitor has been there in the past 10 minutes rather than the day also.

    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 
    $day date('z');
    $year date('Y');
    $hour date('H');
    $seconds date('s');
    $minutes date('i');
    $minutes $minutes 60;
    $hour $hour 3600;
    $time $hour $minutes $seconds;
    $date1 date('H:i'); 
    $date2 date('m.j.y');
    $hitsfile "log.txt"
    $gethits fopen($hitsfile"a+"); 
    $check fread($gethits9999999999);
    fclose($gethits);
    if (
    $check =<  $time 600 " " $user ) {
    $count "hit.txt"
    $value2 fopen($count"r+"); 
    $entervalue fread($value2999999999); 
    fclose($value2); 
    echo 
    "<div id=\"counter\">" $entervalue "</div>\n</div></div></html>";
    die ;
    }
    else {
    $hitsfile "log.txt"
    $entervalue $entervalue 1
    $count "hit.txt"
    $value fopen($count"w+"); 
    fwrite($value$entervalue); 
    fclose($value); 
    $page $entervalue ". " $date1 ." " $date2 " " $computer .  " " $time " " $user "\n"
    $gethits fopen($hitsfile"a+"); 
    fwrite($gethits$page); 
    fclose($gethits); 
    }
    ?>

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
  •