lesley Posted January 26, 2011 Report Share Posted January 26, 2011 I am using this code below to have random images on my site with unique hyperlinks. All of the hyperlinks go to external domains, and i need a way to know how many times people click on them. Is this possible? <?php $bannerAd[1] = '<a href="http://www.link.com"'>http://www.link.com"'>http://www.link.com"'>http://www.link.com" target="_blank"><img src="http://link.com/images/sample1.jpg" border="0"></a>'; $bannerAd[2] = '<a href="http://www.link.com" target="_blank"><img src="http://link.com/images/sample2.jpg" border="0"></a>'; $bannerAd[3] = '<a href="http://www.link.com" target="_blank"><img src="http://link.com/images/sample3.jpg" border="0"></a>'; $bannerAd[4] = '<a href="http://www.link.com" target="_blank"><img src="http://link.com/images/sample4.jpg" border="0"></a>'; $adCount = count($bannerAd); $randomAdNumber = mt_rand(1, $adCount); echo $bannerAd[$randomAdNumber]; ?> Quote Link to comment Share on other sites More sharing options...
falkencreative Posted January 26, 2011 Report Share Posted January 26, 2011 Yes, it is possible. One way to do it: -- instead of linking directly to the link, you link to an intermediary page (for example, "links.php".) You would include an id value of some sort within the link, like links.php?id=[id of link] or (probably easier) the url to the page the user will visit: links.php?url=[full url of link] -- PHP will then be used to get the id or url from the page URL. It will then need to update the total number of times the link has been clicked, either by updating a row within a MySQL database (probably easiest) or a flat text file. -- once the file or database has been updated, you could use the header() function to redirect the user to the site they want to visit. This process will happen almost instantaneously, so the end user shouldn't ever see this .php page in the middle. However, it lets you keep track of the number of clicks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.