SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Hit counter

  1. #1
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,
    I wrote a link script whit a txt db (no mysql available).
    the txt file:
    number(1 to 6)||url||description||naam||email||hits

    example

    4||http://ibwd.cjb.net||iBram Webdesign||iBram007||ibram007@hotmail.com||15

    Everything works fine, except my hit counter:
    PHP Code:
    if(isset($go)){
     
    $filename $url_file;
     
    $file fopen("$filename""r"); 
     if(isset(
    $filename)) { 
      
    $content fgets($file10000);
      
    $splitter explode("||",$content);
      
    $count $splitter[5];
      
    $url $splitter[1];
      
    fclose($file); 
     }
     
     while (isset(
    $filename)){
     
    $file fopen("$filename""r+");
    $count2 $count 1;
     if (
    strstr($go,$url)){
        
    str_replace($splitter,$count2,$count);
        echo
    "<script language=\"Javascript\">location.href='$go';</script>";
        
     }
    else{ echo
    "<!-- $go is not set... -->"; }
    }
    fclose($file);
     } 
    Normaly this script works, but it never do +1 when I call link.php?go=http://ibwd.cjb.net , the hit# always stays at 0...

  2. #2
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can somebody help me please?
    it's pretty urgent

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately you canot just add one to the count you will need to read in the entire text file to php increment the number then write it all back, a database would be better for this. But with txt files you could

    PHP Code:
    <?
    $url_file 
    "links.txt";
    if(isset(
    $go)){
        
    $filename $url_file;
        if(isset(
    $filename)) { 
            
    $file file($filename); 
            foreach(
    $file as $key => $val) {
                
    $splitter explode("||",$val);
                
    $tmp[] = array("ID" => chop($splitter[0]),
                               
    "url" => chop($splitter[1]),
                               
    "desc" => chop($splitter[2]),
                               
    "name" => chop($splitter[3]),
                               
    "email" => chop($splitter[4]),
                               
    "count" => chop($splitter[5])
                               );
                }
            }
        
    reset($tmp);
        foreach(
    $tmp as $key => $val) {
            if (
    strstr($go,$tmp[$key]["url"])){
                
    $tmp[$key]["count"] = $tmp[$key]["count"] + 1;
                }
            }

        
    reset($tmp);

        
    $fp fopen($filename"w");
        foreach(
    $tmp as $key => $val) {
            
    fwrite($fpimplode("||"$tmp[$key])."\n");
            }
        
    fclose($file);
        echo
    "<script language=\"Javascript\">location.href='$go';</script>";
        }
    else{ 
        echo
    "\go is not set... "
        }


    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this line:
    PHP Code:
    foreach($file as $key => $val) { 
    gives:

    Fatal error: Call to unsupported or undefined function foreach()... server path + line

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Step 1: Get latest release of PHP4.

    Step 2: If Step 1 fails change the following line in the script to this in both places it appears.

    PHP Code:
    foreach($tmp as $key => $val) { 
    to

    PHP Code:
    while(list($key,$val) = each ($tmp)) { 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •