Reputation: 3
I am trying to count clicks on external links - which I seem to have achieved - but I am using a text link a database and the header command to redirect.
I would have like it end up with both the external web site and the original page in the browser but I don't think this seems to be possible using the header command alone. Putting them together the other just overwrites the first one.
I need the redirect code to be in the same page as the external links, as I need the web stats to say the link came from a page called count.php - (I am running a directory and hopefully people will pay for advertising on pages that perform well for them).
I don't want to use Javascript for the external link redirect in case someone hasn't got Javascript enabled - this link must work.
Is there a way of also incorporating some code, Javascript maybe, that will enable the original page to be available in the browser, even if it isn't guaranteed to work for everyone.
Upvotes: 0
Views: 77
Reputation: 1246
Link tracking can be done in numerous ways. First make the links to the external pages reside inside anchor links that have targets set to _blank this will open in a new tab or window for the user.
Next have the src of that anchor link go to another page on your domain (this page will control the redirect and the count) - also make sure to pass a parameter in the url to indicate either what link it was for or any other useful value you want to count.
Then use PHP to on this new page to take the url parameters and store them in your DB that is logging the number of clicks. You can do this by matching the URL parameter that contains which link was clicked with the corresponding DB field and add a ++ to the variable you store it in then rewrite it to the DB.
Then use the Header redirect to send them to the external link.
Upvotes: 1