Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 New Website Hitcounter With Images

View previous topic View next topic Go down 
AuthorMessage
SKiddie
Member
Member
SKiddie

Posts : 9
Join date : 2011-05-11

New Website Hitcounter With Images Empty
PostSubject: New Website Hitcounter With Images   New Website Hitcounter With Images EmptyWed May 11, 2011 10:53 pm

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 = 6 - $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 = 6 - $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!!!
Back to top Go down
Understand
Member
Member
Understand

Posts : 21
Join date : 2011-03-09

New Website Hitcounter With Images Empty
PostSubject: Re: New Website Hitcounter With Images   New Website Hitcounter With Images EmptyWed May 11, 2011 10:54 pm

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:
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', 1, time()+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.
Back to top Go down
SKiddie
Member
Member
SKiddie

Posts : 9
Join date : 2011-05-11

New Website Hitcounter With Images Empty
PostSubject: Re: New Website Hitcounter With Images   New Website Hitcounter With Images EmptyWed May 11, 2011 10:55 pm

Did it works now(after the change?)
Back to top Go down
SKiddie
Member
Member
SKiddie

Posts : 9
Join date : 2011-05-11

New Website Hitcounter With Images Empty
PostSubject: Re: New Website Hitcounter With Images   New Website Hitcounter With Images EmptyWed May 11, 2011 10:56 pm

Understand wrote:
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:
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', 1, time()+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!
Back to top Go down
SKiddie
Member
Member
SKiddie

Posts : 9
Join date : 2011-05-11

New Website Hitcounter With Images Empty
PostSubject: Re: New Website Hitcounter With Images   New Website Hitcounter With Images EmptyWed May 11, 2011 10:56 pm

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
Back to top Go down
Twerk
Member
Member
Twerk

Posts : 26
Join date : 2011-04-17

New Website Hitcounter With Images Empty
PostSubject: Re: New Website Hitcounter With Images   New Website Hitcounter With Images EmptyWed May 11, 2011 10:57 pm

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??
Back to top Go down
Understand
Member
Member
Understand

Posts : 21
Join date : 2011-03-09

New Website Hitcounter With Images Empty
PostSubject: Re: New Website Hitcounter With Images   New Website Hitcounter With Images EmptyWed May 11, 2011 11:00 pm

SKiddie wrote:

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:

Code:

print '<img src="../IMG/' . $sTxt[$i] . '.bmp" />';
// not
print '<img src="../IMG/' . $sTxt[$i] . '.bmp' />"; 

i added this

Code:

if (isset($_COOKIE['countplus']) && $_COOKIE['countplus'] != 1)
{
    ++$txt;
    file_put_contents("counter.txt", $txt); 
    setcookie('countplus', 1, time()+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:

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.

I should probably put the end in. I'd expect that this will work, but with most of what I do it is untested:
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', 1, time()+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" />';
}
?>
Back to top Go down
SKiddie
Member
Member
SKiddie

Posts : 9
Join date : 2011-05-11

New Website Hitcounter With Images Empty
PostSubject: Re: New Website Hitcounter With Images   New Website Hitcounter With Images EmptyWed May 11, 2011 11:01 pm

Understand wrote:
SKiddie wrote:

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:

Code:

print '<img src="../IMG/' . $sTxt[$i] . '.bmp" />';
// not
print '<img src="../IMG/' . $sTxt[$i] . '.bmp' />"; 

i added this

Code:

if (isset($_COOKIE['countplus']) && $_COOKIE['countplus'] != 1)
{
    ++$txt;
    file_put_contents("counter.txt", $txt); 
    setcookie('countplus', 1, time()+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:

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.

I should probably put the end in. I'd expect that this will work, but with most of what I do it is untested:
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', 1, time()+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" />';
}
?>

n this case we need to use or isset() or !=1
Back to top Go down
SKiddie
Member
Member
SKiddie

Posts : 9
Join date : 2011-05-11

New Website Hitcounter With Images Empty
PostSubject: Re: New Website Hitcounter With Images   New Website Hitcounter With Images EmptyWed May 11, 2011 11:01 pm

Can't I Get something wrong I have only 12 Years
Back to top Go down
Tiger
Member
Member
Tiger

Posts : 7
Join date : 2011-04-17

New Website Hitcounter With Images Empty
PostSubject: Re: New Website Hitcounter With Images   New Website Hitcounter With Images EmptyWed May 11, 2011 11:02 pm

Twerk wrote:
You don't feel hit counters and digital-style digits are outdated??

No way, every guestbook/shoutbox needs one.
Back to top Go down
Sponsored content




New Website Hitcounter With Images Empty
PostSubject: Re: New Website Hitcounter With Images   New Website Hitcounter With Images Empty

Back to top Go down
 

New Website Hitcounter With Images

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» Images of different sizes
» background images overlapping
» Photography website
» i'm trying to add iframes to my website...
» Save the pictures from google images search page

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: New Website Hitcounter With Images Edit-trash Useless :: Trash-