Forum Moderators: DixonJones

Message Too Old, No Replies

tracking link clicks

         

jackvull

4:10 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



I have some PHP pages with links to certain files that are downloaded. Normally, when you click on these in a browser, the file is downloaded to your computer. Ideally, I want to track these clicks and add a record to a MySQL database.
Any ideas on how to do this?

Thanks.

Dijkgraaf

11:20 pm on Jun 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Rather than giving them a direct link to the file, have the link go to a page that then records their visit and then starts the download.

jackvull

8:42 am on Jun 22, 2005 (gmt 0)

10+ Year Member



OK, I can see how that would work but is there an easy way to start a download of a file within PHP?
I don't want to use JavaScript for this in case the client browser is not the correct version, or doesn't have it installed.

jackvull

8:43 am on Jun 22, 2005 (gmt 0)

10+ Year Member



Could I direct them to a hidden iframe in the same page that would do this?

larryn

12:19 pm on Jun 22, 2005 (gmt 0)

10+ Year Member



Jack,

In PHP, the easyiest way would be to use a location header to redirect the browser to the download after you have completed your logging.

An alternative but one that requires some Javascript, is to make your log database entry via the anchor's onClick event.

Larry

jackvull

4:06 pm on Jun 22, 2005 (gmt 0)

10+ Year Member



Ok, thanks. I can see how that would work but some users currently right click and select 'save target as...'. How would redirecting cope with this?
Is there a way to force whether the request is for:
(a) download and save;
(b) download and play within IE / Mozilla.