[web] Registering clicks on a link
I have an image link on one site that redirects to another web site on a seperate server. I need to figure out how to store the number of times people have clicked on the link. Does anyone have any ideas?
Sure. Just have the link send the user to a php page that stores the hit in a database, then foward the user to the correct page from there. You'd have to know PHP and MySql (though, very little of it), but... its do-able.
The example would look like this.
This is the page with the link:
then, the store_link.php file would look something LIKE this (PS THIS IS A VERY CRUDE VERSION OF WHAT STORE_LINK.PHP SHOULD LOOK LIKE).
I hope that helps.
The example would look like this.
This is the page with the link:
.....<a href = "store_link.php?value=www.thispage.com><img src.....></a>
then, the store_link.php file would look something LIKE this (PS THIS IS A VERY CRUDE VERSION OF WHAT STORE_LINK.PHP SHOULD LOOK LIKE).
<?phpglobal $HTTP_GET_VARS;require_once('all_my_php_functions.php');$Link = $HTTP_GET_VARS['value'];$Conn = db_connect();mysql_query("Update DBTABLE set Hits = Hits + 1 where Link = '$Link'");?><html><head><...insert whatever the code is here to foward the user ='<?php echo $Link; ?>' ></head></html>
I hope that helps.
Please do not just include outside data into a query string. This opens up an SQL injection attack. At the very least you'll want something like
$Conn = db_connect();$Link = mysql_real_escape_string($HTTP_GET_VARS['value'], $Conn);mysql_query("Update DBTABLE set Hits = Hits + 1 where Link = '$Link'");
Oh and please use $_GET rather than $HTTP_GET_VARS, the latter is now officially deprecated, and there are a number of reasons why as well.
And the only thing you need to do to forward a user to another location is use the header() function, no HTML necessary.
And the only thing you need to do to forward a user to another location is use the header() function, no HTML necessary.
$_GET has been around since 4.1 and is automatically global. You dont need to do global $_GET like you do with $HTTP_GET_VARS
source
source
Hmm.. you're right. By definition, it is depricated. However, if you're running a version of php that is pre-4.1... then you can't user $_GET. But then agian, may God help you if you're host is running a pre-4.1 version of PHP.
Quote:Original post by Cygnus_X
But then agian, may God help you if you're host is running a pre-4.1 version of PHP.
Amen.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement