Page 1 of 1

Link counter / Redirection

Posted: Wed Jun 05, 2002 12:08 pm
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.

Posted: Wed Jun 05, 2002 1:39 pm
by jason
After you update the Database, simply use this:

Code: Select all

<?php
header("Location: http://www.example.com/");
?>

Posted: Wed Jun 05, 2002 1:42 pm
by Shadough

Code: Select all

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

Code: Select all

header("Location: $url");
exit;

Posted: Wed Jun 05, 2002 1:57 pm
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

Posted: Wed Jun 05, 2002 7:41 pm
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

Posted: Thu Jun 06, 2002 4:08 am
by f1nutter
Thanks guys, I've got it working. :D
As I use PHP more, you will be hearing from me again!