[SOLVED] Link System

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

[SOLVED] Link System

Post by Sphen001 »

Hi,

I'm trying to create a link type system which counts the number of clicks a certain link has. Right now, the script updates the count in the DB, and then redirects to the URL via a META redirect. Is there a better way? I've tried it by using header redirects, but get header_already_sent messages.

Thanks for your help :D

Sphen001
Last edited by Sphen001 on Tue Jul 12, 2005 9:18 pm, edited 1 time in total.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Code: Select all

location.href='http://www.yousite.com'
(Javascript)

The database is fine for keeping track of clicks.
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

Post by Sphen001 »

Hi,

Thanks a lot. That's very cool. I have one tiny problem with that. There is the problem that this system is going to be distributed, and because JavaScript can be turned off in the browser, a problem emerges. I like the idea though. If there are any more ideas, I'd love to hear them.

Thanks,

Sphen001
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you're getting header already sent messages because you have output some form of data before the header() functions get called.

Have a read: viewtopic.php?t=1157
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

Post by Sphen001 »

Hi,

Sorry, I should have said that I already know why I'm getting the errors. Right now, I'm using META, and I would like to do something a bit less undetectable, but I can't think of anything that would work. I have thought about doing output buffering, but that would require a complete rewrite of my whole script. I'm keeping it in mind though. Also, I'm wondering if there's a faster way to update the database. Right now, I'm getting the count from the DB, adding one, and then updating the DB. Is there some way that I could do that a bit faster, maybe without so many queries?

Thanks,

Sphen001
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it can be done in a single query

Code: Select all

UPDATE `table` SET `field` = `field` + 1 WHERE `id` = '24'
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

Post by Sphen001 »

Awesome!

Thanks so much

Sphen001
Post Reply