Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hey guys, I had someone tell me today that they put a counter on their social network page, I find this hard to believe because most of these pages have javascript or php shut off. He says that it is an image that has a url on it pointing to the site the image is hosted at. I dont believe this is true but wanted to see if someone here heard of this and if thay have how could i go abouts making the script?

Simple create the image link on the page something like this (added spaces so code wouldn't be interpreted by forum):
[img src="ht tp://ww w.yoursite.com/imagecounter.php"]Then create the page something like this
<?php//Add code here to count the
//hit and save to db or file//Display the image
header('Location: myimage.jpg');?>
Alternatively you could have the code dynamically CREATE an image for the counter and show that.
http://www.phpjunkyard.com/php-grap...Michael J

BUt wouldn't that only work if someone clicked the image. I need it to automatically count everytime the page is loaded. Remember, none of these social networks allow javascript or php to run freely, it is limited at best.

No, there is no "onclick" parameter in that image tag. When the HTML page loads and sees the img tag the user's browser will attempt to load the image from the location specified in the src attribute. That will trigger the PHP page that will first perform the "counter" fuction before providing the image to the user.
The link I provided should have everything you need.
Michael J

Alright, so i understand how to do the counter. The site that you linked to talks about using javascript, i cant use any script on the page. None the less i can do the counter but what if i wanted to do a unique count, how could i achieve this?

What do you mena by a "unique" count? Unique per visitor? You could try IP address, but that won't be accurate since multiple users would be using the same IP address if on a private network behind a router.
Michael J

a unique visit would be based on someone visiting the site in the same day. basically i want to make it so that if a visitor visits the site within a 24 hour period it only counts as one visit, this helps see how many different peple visit in a day. Nothing would truly be accurate unless scripting was completely allowed. How could i grab an ip address with the image link?

Nothing would truly be accurate unless scripting was completely allowed. How could i grab an ip address with the image link?
But, as I just displayed above you can use scripting. Simply use an image tag and make the src of that tag point to a PHP page on your server. That page can do whatever scripting you want to do and ultimately return an image to the browser.
I don't know how to put it more simply than the fact that the src of an image tag can be anything - including the url to a php page. The browser will attempt to load that source. In the case of php you can do whatever processing you want, but only return an image resource so the user has no knowledge of what happened.
Now that's not to say that whatever site you are referring to does not try and block that, but it may not.
This is nothing different than many SPAM HTML emails that use images to track which emails are opened by users. The email contains an image with a link such as somepage.php?user=dummy@domain.com
When the user opens their email the application will try to load the image. The identifyer on the url tells the receiving page who opened the email and they then know the email is valid. That is why so many email applications no longer load images by default.
Michael J

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |