Jump to content
Killersites Forums

PHP Banner Count

Recommended Posts

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?






$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];


Link to post
Share on other sites

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.

Link to post
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...