By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,190 Members | 1,469 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,190 IT Pros & Developers. It's quick & easy.

Question about encapsulating PHP script inside an anchor

P: n/a
Here's an interesting problem -

On one of my pages, I have a place where a user can download a
ZIP file by clicking on the phrase "Click to download". I want
to call a logging function that I use to show that the file was
downloaded. The file being downloaded is called file1.zip.

What I now do is the following:

<a href= "..\..\downloads\file1.zip">
<?php logvisitor('file1.zip'); ?>Click to download.</a>

which produces the following HTML

<a href = "..\..\downloads\file1.zip" >Click to download.</a>
So far so good.

But -- here's the problem -- the function logvisitor() is
always called even if the user didn't click on the link.
By placing the PHP function inside the anchor, I had assumed
it too would only be called if the user clicked.

I've also tried the following:

<a href="<?php logvisitor('file1.zip');
echo '..\..\downloads\file1.zip'; ?> >
Click here to download.</a>

and get the same result, namely, that the PHP function is
always called.

Anybody know how to call the function if and only if the
user clicks on the phrase?
--
Jim
Jul 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"JimC" <ji**@cross-comp.com> skrev i en meddelelse
news:kA*******************@newssvr14.news.prodigy. com...
On one of my pages, I have a place where a user can download a
ZIP file by clicking on the phrase "Click to download". I want
to call a logging function that I use to show that the file was
downloaded. The file being downloaded is called file1.zip. You could write a script that returns the requested file and logs the
download when called like this:
download.php?file=..\..\downloads\file1.zip
('\' will perhaps have to be urlencoded)
What I now do is the following:

<a href= "..\..\downloads\file1.zip">
<?php logvisitor('file1.zip'); ?>Click to download.</a>

PHP is evaluated serverside, that is before the html is sent to the client,
so you can't do this..
Martin
Jul 16 '05 #2

P: n/a
RG

"Martin C. Petersen" <mc*@phys.au.dk> wrote in message
news:3f***********************@dtext01.news.tele.d k...
"JimC" <ji**@cross-comp.com> skrev i en meddelelse
news:kA*******************@newssvr14.news.prodigy. com...
On one of my pages, I have a place where a user can download a
ZIP file by clicking on the phrase "Click to download". I want
to call a logging function that I use to show that the file was
downloaded. The file being downloaded is called file1.zip. You could write a script that returns the requested file and logs the
download when called like this:
download.php?file=..\..\downloads\file1.zip
('\' will perhaps have to be urlencoded)
What I now do is the following:

<a href= "..\..\downloads\file1.zip">
<?php logvisitor('file1.zip'); ?>Click to download.</a>

PHP is evaluated serverside, that is before the html is sent to the

client, so you can't do this..
Martin

What you need to do is this:
<a href="downloadandlog.php?file=file1.zip">Download</a>

Then in downloadandlog.php:
get $file
write to the log
use the header function to send the file

Hope this helps
RG

Jul 16 '05 #3

P: n/a


Martin C. Petersen wrote:
"JimC" <ji**@cross-comp.com> skrev i en meddelelse
news:kA*******************@newssvr14.news.prodigy. com...
On one of my pages, I have a place where a user can download a
ZIP file by clicking on the phrase "Click to download". I want
to call a logging function that I use to show that the file was
downloaded. The file being downloaded is called file1.zip.


You could write a script that returns the requested file and logs the
download when called like this:
download.php?file=..\..\downloads\file1.zip
('\' will perhaps have to be urlencoded)

What I now do is the following:

<a href= "..\..\downloads\file1.zip">
<?php logvisitor('file1.zip'); ?>Click to download.</a>


PHP is evaluated serverside, that is before the html is sent to the client,
so you can't do this..

Heh, but of course! Dunno what came over me.

Jim

Jul 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.