Question about encapsulating PHP script inside an anchor

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JimC

    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


  • Martin C. Petersen

    #2
    Re: Question about encapsulating PHP script inside an anchor

    "JimC" <jimc@cross-comp.com> skrev i en meddelelse
    news:kAPQa.92$I c5.11602109@new ssvr14.news.pro digy.com...[color=blue]
    > 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.[/color]
    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)
    [color=blue]
    > What I now do is the following:
    >
    > <a href= "..\..\download s\file1.zip">
    > <?php logvisitor('fil e1.zip'); ?>Click to download.</a>[/color]
    PHP is evaluated serverside, that is before the html is sent to the client,
    so you can't do this..


    Martin


    Comment

    • RG

      #3
      Re: Question about encapsulating PHP script inside an anchor


      "Martin C. Petersen" <mcp@phys.au.dk > wrote in message
      news:3f13c70f$0 $83067$edfadb0f @dtext01.news.t ele.dk...[color=blue]
      > "JimC" <jimc@cross-comp.com> skrev i en meddelelse
      > news:kAPQa.92$I c5.11602109@new ssvr14.news.pro digy.com...[color=green]
      > > 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.[/color]
      > 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)
      >[color=green]
      > > What I now do is the following:
      > >
      > > <a href= "..\..\download s\file1.zip">
      > > <?php logvisitor('fil e1.zip'); ?>Click to download.</a>[/color]
      > PHP is evaluated serverside, that is before the html is sent to the[/color]
      client,[color=blue]
      > so you can't do this..
      >
      >
      > Martin
      >
      >[/color]


      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



      Comment

      • JimC

        #4
        Re: Question about encapsulating PHP script inside an anchor



        Martin C. Petersen wrote:[color=blue]
        > "JimC" <jimc@cross-comp.com> skrev i en meddelelse
        > news:kAPQa.92$I c5.11602109@new ssvr14.news.pro digy.com...
        >[color=green]
        >>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.[/color]
        >
        > 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)
        >
        >[color=green]
        >>What I now do is the following:
        >>
        >> <a href= "..\..\download s\file1.zip">
        >> <?php logvisitor('fil e1.zip'); ?>Click to download.</a>[/color]
        >
        > PHP is evaluated serverside, that is before the html is sent to the client,
        > so you can't do this..[/color]


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

        Jim

        Comment

        Working...