Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile New Website Hitcounter With Images

    PHP Code:
    <?php
    if($_COOKIE["countplus"] != 1)
    {
    $txt file_get_contents("counter.txt");
    $txt++;
    file_put_contents("counter.txt"$txt); 
    $txt file_get_contents("counter.txt");
    $l strlen($txt);
    $nrofo $l;

    for (
    $i 0$i <= $nrofo$i++) {
        echo 
    "<img src='../IMG/0.bmp'>";
    }
    for (
    $i 0$i <= $l 1$i++) {
        echo 
    "<img src='../IMG/" $txt[$i] . ".bmp'>";
    }
    setcookie("countplus""1"time()+60*60*24);
    } else 
    {
    $txt file_get_contents("counter.txt");
    $l strlen($txt);
    $nrofo $l;

    for (
    $i 0$i <= $nrofo$i++) {
        echo 
    "<img src='../IMG/0.bmp'>";
    }
    for (
    $i 0$i <= $l 1$i++) {
        echo 
    "<img src='../IMG/" $txt[$i] . ".bmp'>";
    }

    }
    ?>
    This code is 100% working!!!



    These are the digits just copy all in a folder called IMG that is in the same dir as the script(the folder)

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    This would actually belong in the snippets forum.
    There is too much work happening in here. The code is replicated for both the cookie and non cookied approaches. This can be factored down to this:
    PHP Code:
    <?php

    $iPad 
    10;
    $txt file_get_contents("counter.txt");

    if (isset(
    $_COOKIE['countplus']) && $_COOKIE['countplus'] != 1)
    {
        ++
    $txt;
        
    file_put_contents("counter.txt"$txt);  
        
    setcookie('countplus'1time()+86400);
    }

    $sTxt str_pad($txt$iPad'0'STR_PAD_LEFT);
    $iTxtLength strlen($sTxt);
    for (
    $i 0$i $iTxtLength; ++$i)
    {
        print 
    '<img src="../IMG/' $sTxt[$i] . '.bmp' />";
    }
    ?>
    I didn't do anything to trap errors or change the file handling.

    I would go a completely different way and use the GD to overlay the images together and kick out a script that is served as an image. The pro is that you have one image, the con is that it takes more work to do.

  • Users who have thanked Fou-Lu for this post:

    ionutica (05-10-2011)

  • #3
    New to the CF scene
    Join Date
    May 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Did it works now(after the change?)

  • #4
    New to the CF scene
    Join Date
    May 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    This would actually belong in the snippets forum.
    There is too much work happening in here. The code is replicated for both the cookie and non cookied approaches. This can be factored down to this:
    PHP Code:
    <?php

    $iPad 
    10;
    $txt file_get_contents("counter.txt");

    if (isset(
    $_COOKIE['countplus']) && $_COOKIE['countplus'] != 1)
    {
        ++
    $txt;
        
    file_put_contents("counter.txt"$txt);  
        
    setcookie('countplus'1time()+86400);
    }

    $sTxt str_pad($txt$iPad'0'STR_PAD_LEFT);
    $iTxtLength strlen($sTxt);
    for (
    $i 0$i $iTxtLength; ++$i)
    {
        print 
    '<img src="../IMG/' $sTxt[$i] . '.bmp' />";
    }
    ?>
    I didn't do anything to trap errors or change the file handling.

    I would go a completely different way and use the GD to overlay the images together and kick out a script that is served as an image. The pro is that you have one image, the con is that it takes more work to do.
    Oh, here is a error
    print '<img src="../IMG/' . $sTxt[$i] . '.bmp' />";
    use
    echo "<img src='../IMG/$sTxt[$i].bmp' />";
    print is outdated!

  • #5
    New to the CF scene
    Join Date
    May 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    And you got the part with isset because the cookie will be inexistent or = to 1
    so it will never be equal to 2 or 3 or 0 no it will be equal to "" not set but != 1

  • #6
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Quote Originally Posted by ionutica View Post
    Oh, here is a error
    print '<img src="../IMG/' . $sTxt[$i] . '.bmp' />";
    use
    echo "<img src='../IMG/$sTxt[$i].bmp' />";
    print is outdated!
    The original was entirely fine... nothing wrong with using print(), it's perfectly acceptable.

    You don't feel hit counters and digital-style digits are outdated??
    Last edited by kbluhm; 05-10-2011 at 08:31 PM.

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by ionutica View Post
    Oh, here is a error
    print '<img src="../IMG/' . $sTxt[$i] . '.bmp' />";
    use
    echo "<img src='../IMG/$sTxt[$i].bmp' />";
    print is outdated!
    what do you mean?

    best regards

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by ionutica View Post
    Oh, here is a error
    print '<img src="../IMG/' . $sTxt[$i] . '.bmp' />";
    use
    echo "<img src='../IMG/$sTxt[$i].bmp' />";
    print is outdated!
    print will never be deprecated as its linked to the core C printf. Since it is a language construct, it would be a tremendous overhaul to remove it. And we know that's not going anywhere. Though there is an error, I have the ending ' and " in the wrong order there, that should have been:
    PHP Code:
    print '<img src="../IMG/' $sTxt[$i] . '.bmp" />';
    // not
    print '<img src="../IMG/' $sTxt[$i] . '.bmp' />"; 
    Quote Originally Posted by ionutica View Post
    And you got the part with isset because the cookie will be inexistent or = to 1
    so it will never be equal to 2 or 3 or 0 no it will be equal to "" not set but != 1
    I haven't a clue what you are talking about here. I added this:
    PHP Code:
    if (isset($_COOKIE['countplus']) && $_COOKIE['countplus'] != 1)
    {
        ++
    $txt;
        
    file_put_contents("counter.txt"$txt);  
        
    setcookie('countplus'1time()+86400);

    as my impression of what the intent was is to only count up if there is no cookie currently set.
    Oh wait, I see. That is backwards, I originally wrote it thinking you were only counting if countplus was available, but realized that it was the other way around. That should be:
    PHP Code:
    if (!isset($_COOKIE['countplus']) || $_COOKIE['countplus'] != 1
    This way if there is no cookie OR if there is a cookie and its value is not 1, that it will increment the counter and set the cookie.

    Edit:
    I should probably put the end in. I'd expect that this will work, but with most of what I do it is untested:
    PHP Code:
    <?php

    $iPad 
    10;
    $txt file_get_contents("counter.txt");

    if (!isset(
    $_COOKIE['countplus']) || $_COOKIE['countplus'] != 1)
    {
        ++
    $txt;
        
    file_put_contents("counter.txt"$txt);  
        
    setcookie('countplus'1time()+86400);
    }

    $sTxt str_pad($txt$iPad'0'STR_PAD_LEFT);
    $iTxtLength strlen($sTxt);
    for (
    $i 0$i $iTxtLength; ++$i)
    {
        print 
    '<img src="../IMG/' $sTxt[$i] . '.bmp" />';
    }
    ?>
    Last edited by Fou-Lu; 05-10-2011 at 11:26 PM.

  • #9
    New to the CF scene
    Join Date
    May 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    print will never be deprecated as its linked to the core C printf. Since it is a language construct, it would be a tremendous overhaul to remove it. And we know that's not going anywhere. Though there is an error, I have the ending ' and " in the wrong order there, that should have been:
    PHP Code:
    print '<img src="../IMG/' $sTxt[$i] . '.bmp" />';
    // not
    print '<img src="../IMG/' $sTxt[$i] . '.bmp' />"; 


    I haven't a clue what you are talking about here. I added this:
    PHP Code:
    if (isset($_COOKIE['countplus']) && $_COOKIE['countplus'] != 1)
    {
        ++
    $txt;
        
    file_put_contents("counter.txt"$txt);  
        
    setcookie('countplus'1time()+86400);

    as my impression of what the intent was is to only count up if there is no cookie currently set.
    Oh wait, I see. That is backwards, I originally wrote it thinking you were only counting if countplus was available, but realized that it was the other way around. That should be:
    PHP Code:
    if (!isset($_COOKIE['countplus']) || $_COOKIE['countplus'] != 1
    This way if there is no cookie OR if there is a cookie and its value is not 1, that it will increment the counter and set the cookie.

    Edit:
    I should probably put the end in. I'd expect that this will work, but with most of what I do it is untested:
    PHP Code:
    <?php

    $iPad 
    10;
    $txt file_get_contents("counter.txt");

    if (!isset(
    $_COOKIE['countplus']) || $_COOKIE['countplus'] != 1)
    {
        ++
    $txt;
        
    file_put_contents("counter.txt"$txt);  
        
    setcookie('countplus'1time()+86400);
    }

    $sTxt str_pad($txt$iPad'0'STR_PAD_LEFT);
    $iTxtLength strlen($sTxt);
    for (
    $i 0$i $iTxtLength; ++$i)
    {
        print 
    '<img src="../IMG/' $sTxt[$i] . '.bmp" />';
    }
    ?>
    In this case we need to use or isset() or !=1

  • #10
    New to the CF scene
    Join Date
    May 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Can't I Get something wrong I have only 12 Years

  • #11
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by kbluhm View Post
    You don't feel hit counters and digital-style digits are outdated??
    No way, every guestbook/shoutbox needs one.

  • #12
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Quote Originally Posted by Inigoesdr View Post
    No way, every guestbook/shoutbox needs one.

  • #13
    New to the CF scene
    Join Date
    May 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Do you like it? Add to my reputation!!!

  • #14
    New to the CF scene
    Join Date
    Sep 2011
    Location
    the matrix
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 Post
    the digit images on the first post don't load


  •  

    Tags for this Thread

    Posting Permissions

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