Jump to content
  • Advertisement
Sign in to follow this  
ezacharyk

[web] Registering clicks on a link

This topic is 4370 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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:


.....
<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).



<?php

global $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.

Share this post


Link to post
Share on other sites
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'");

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!