Image Link Counter
Ok, heres what I am wanting to do. I am wanting to post a bunch of images in a .php page, but I want to know how many times they have been clicked, and have that # of times they have been clicked to show under the image. I have searched the web and havent found anything TOO helpful in my cause, can some of you geniouses lend me some coding, or help me do this? Thanks!
Renegade posted this at 05:05 — 2nd November 2004.
He has: 3,022 posts
Joined: Oct 2002
Well, one way I can think of is to use a redirect page, which works something similar to this:
1, user clicks on image
2, user goes to a page for a second which runs a PHP program to update the number of image views then gets redirected to the actual image.
of course, once a user has the actual url of the image... whats to stop them from giving it to a friend to have a look at? wouldn't that mess up the counter and give "false" results?
Busy posted this at 09:51 — 2nd November 2004.
He has: 6,151 posts
Joined: May 2001
offer the linked thumbnails (with counter underneath), on the image page (viewing full image) add one to the database value (of course each image has an id of some sort)
this counter is displayed on the thumbnail page, just set database so default is 0
This way even if they did go directly to the image it would still count the hit, as long as the page was opened it will count it.
If you are drawing the image name from the database, this is even easier as you already have a unquie id, if you aren't then you will have to add a id to the url or something.
Lamur posted this at 06:15 — 7th November 2004.
They have: 25 posts
Joined: Aug 2004
So how would I draw the image from the database, say MySQL, and assign a Unique ID to each image? I am fairly new to this, I appologize.
Busy posted this at 10:43 — 7th November 2004.
He has: 6,151 posts
Joined: May 2001
You haven't given much details on your set up or methods but the following can be added to.
You could set up your main database and have imageid (auto increment), image name, description, caption, views, votes ... whatever you want. If you want the works it may be better to seperate the view, votes and possibly the caption (whatever is called without seeing the big image) into another row.
CREATE TABLE imagelog (
imageid int(5) NOT NULL auto_increment,
imagename varchar(25) NOT NULL,
views int(5) NOT NULL default '0',
caption varchar(50) NOT NULL,
PRIMARY KEY (imageid),
UNIQUE KEY pid (imageid),
KEY imageid_2 (imageid)
) TYPE=MyISAM;
the numbers in brackets can be changed to whatever, int = number and 5 would allow up to 99999, varchar = text and numbers, well everything really and 50 equals 50 total characters (including spaces) example: it's my sentence
16 long but it starts at 0 . the 25 limit for image name may not be enough, if say you input a name which is 26 characters long you will cut off the end, then when you go to display the image it will only have a .jp (or whatever) extension, so depending how you name your images as to how you determine the length. Some people get carried away, like picture_of_missy_the_cat_chasing_a_shadow_20th_feb_1902.jpg
so every time you add an image name, the imageid will increment one (automatically) and you can id the images via this id name.
The above has not been tested - I just wrote it off top of my head - looks right.
Don't include the images diminsions (width and height) into the databse, you can use PHP's getimagesize() function to get that for you when you display the image, also, hopefullly the thumb and main images have the same name, but with thumbnail having a t_ or something infront, if so only add the main images name, you can add the thumbnail extension when you display it (make sure the t_ is infront of the name, not after like bigpic_t.jpg or you'll be making work for yourself splitting the name etc
If you are a complete novice at PHP/mySQL you could take a look over at hotscripts.com for a ready made script or get your hands dirty and do it yourself.
It's not hard but without knowing details it's like asking how long is a bit of string - the options are endless
Lamur posted this at 18:57 — 7th November 2004.
They have: 25 posts
Joined: Aug 2004
Thanks Busy,
I will give that a shot and see how it works, thanks for all your time.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.