473,546 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about encapsulating PHP script inside an anchor

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= "..\..\download s\file1.zip">
<?php logvisitor('fil e1.zip'); ?>Click to download.</a>

which produces the following HTML

<a href = "..\..\download s\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('fil e1.zip');
echo '..\..\download s\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
3 3566
"JimC" <ji**@cross-comp.com> skrev i en meddelelse
news:kA******** ***********@new ssvr14.news.pro digy.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?fi le=..\..\downlo ads\file1.zip
('\' will perhaps have to be urlencoded)
What I now do is the following:

<a href= "..\..\download s\file1.zip">
<?php logvisitor('fil e1.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
RG

"Martin C. Petersen" <mc*@phys.au.dk > wrote in message
news:3f******** *************** @dtext01.news.t ele.dk...
"JimC" <ji**@cross-comp.com> skrev i en meddelelse
news:kA******** ***********@new ssvr14.news.pro digy.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?fi le=..\..\downlo ads\file1.zip
('\' will perhaps have to be urlencoded)
What I now do is the following:

<a href= "..\..\download s\file1.zip">
<?php logvisitor('fil e1.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="downloada ndlog.php?file= file1.zip">Down load</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


Martin C. Petersen wrote:
"JimC" <ji**@cross-comp.com> skrev i en meddelelse
news:kA******** ***********@new ssvr14.news.pro digy.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?fi le=..\..\downlo ads\file1.zip
('\' will perhaps have to be urlencoded)

What I now do is the following:

<a href= "..\..\download s\file1.zip">
<?php logvisitor('fil e1.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4297
by: JimC | last post by:
Think I asked this once before. My apologies for asking twice. In a certain PHP document at my site, I have a link to a Word version of the same document. If the user downloads it, I want to log that s/he has done this. Data logging isn't the issue. Calling a PHP script is. So what I have is something like: <a...
10
1283
by: Chris Martin | last post by:
Background: Our main menu is built using a simple unordered list containing other ULs. There is a table on a page that holds the subnav. Because of certain circumstances, I need to build the subnav dynamically on each page. I wrote this script in about 15 minutes because it was a "scope-creep" kinda thing. Now that I have a bit of time, for...
2
3936
by: Vaughn | last post by:
Where can I get information on automatic resizing of controls when the form changes size (eg. if I dynamically increase the size of my form, the listview inside should automatically increase in size ). Thanks.
7
1301
by: neverstill | last post by:
hi- I have <a> tags in my DataList. For the href property, I want to do something like this: <a href='~/Default.aspx?show=Support&disp=Faq&p=<%# DataBinder.Eval(Container.DataItem, "name")%>' runat=server>some link</a> Looks pretty straight forward, but when I add the runat=server property it stops parsing the <% %> block correctly.
3
5669
by: Leigh Webber | last post by:
I have an HTMLAnchor control on my aspx page. When it's not inside a repeater, it works fine. When I put it inside a repeater control, the handler never gets fired. I have a handler for the htmlAnchor's ServerClick event (works when not inside a repeater), and a handler for the repeater's ItemCommand event. My html and vb source code is shown...
19
1322
by: landingone | last post by:
How do I add a link to download a *.pdf file in Dreamweaver? I admit I'm not very savvy with this and usually just do a cut and paste from a *.doc document. I inherited this from someone who set up the website. Any help would *greatly* be appreciated!!! Thanks!
1
2023
by: DJ | last post by:
I have a DropDownList in Visual Web Developer that is databound to a SQL Database. Whenever the web page is opened the DropDownList is automatically filled with the first item in the table. My question is, how do I set it so that the DropDownList is empty until a value is selected?
7
3495
by: gordon | last post by:
is it possible to send a message to the gui instance while the Tk event loop is running?I mean after i create a gui object like root=Tk() mygui=SomeUI(root) and call root.mainloop() can i send message to mygui without quitting the ui or closing the
3
1873
DogBot
by: DogBot | last post by:
To define my question I need to establish an example: Let's say I have a web page (MYPAGE.HTML) and this webpage is constrained in width. This web page has 200 lines of text. I have an anchor on line 30 <a name="myanchor"> and a link on the first line that points to that anchor <a href="#myanchor">go to anchor</a> If I click on the link...
0
7507
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5361
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.