Link counter / Redirection

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
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Link counter / Redirection

Post by f1nutter »

Hi folks,
I am trying to set up a links page on my site with a counter that tracks how many times an external link has been followed, and then sort the page with the most popular link at the top (I sure you've all seen this kind of thing!).
I have two files. The link page generator which sorts the links in "hit" order. This is no problem.
When a link is followed the user is taken to link_redirect.php?url=http://www.somewhere.web. The link_redirect.php page extracts the url from the address line, increases the number of hits and writes the new value to the db.
Then the user needs to be taken to the link they have followed, and thats where I need your help.
I have seen something to do with sending headers for redirection, but as I'm new to PHP I am not ready for it!
The scripts were originally written in ASP as I know a little bit more about it. I used Response.Redirect(link) at the end of the script so this was activated when updating the db had been done.
Is this solvable? If I use META redirection how do I know what time to set to give the script long enough to update the db, but not too long that the user is looking at a blank page?

Thanks.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

After you update the Database, simply use this:

Code: Select all

<?php
header("Location: http://www.example.com/");
?>
Shadough
Forum Newbie
Posts: 20
Joined: Tue Jun 04, 2002 9:11 pm

Post by Shadough »

Code: Select all

<meta http-equiv="refresh" content="0;url=<?=$url?>">
Or using header()

Code: Select all

header("Location: $url");
exit;
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

http://www.ice-on-fire.net/~team/scripts.php i wrote a script that counts links, but i have no idea how to sort them since it is flat file
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post by lc »

I wrote the thing below for use with download of files but it works fine with links too. You'll have to adapt it to a single .php file to track all links. But this might give you an idea.

http://www.alienhelpdesk.com/freescripts.php?id=5
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post by f1nutter »

Thanks guys, I've got it working. :D
As I use PHP more, you will be hearing from me again!
Post Reply