browser.history and log file

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

    browser.history and log file

    Hello,
    I am very beginner with PHP. I have an Apache PHP enabled
    webserver and want to know from where users are coming from.
    Understand I want the last surfer's browser visited url.
    I imagine I can do this with some kind of interraction
    between 2 scripts : one client side, one server side.
    The client one send the URL and the server one write it
    in the right log file.
    I have no idea of how to do this nor with principle nor
    with syntax ...
    Can somebody help with a few lines *working* example?
    Any idea appreciated!
    Thanks
    Rg.
  • kingofkolt

    #2
    Re: browser.history and log file

    "Rg" <spam@me.agai n> wrote in message
    news:Xns95437C0 855428spammeaga in@195.131.52.1 35...[color=blue]
    > Hello,
    > I am very beginner with PHP. I have an Apache PHP enabled
    > webserver and want to know from where users are coming from.
    > Understand I want the last surfer's browser visited url.
    > I imagine I can do this with some kind of interraction
    > between 2 scripts : one client side, one server side.
    > The client one send the URL and the server one write it
    > in the right log file.
    > I have no idea of how to do this nor with principle nor
    > with syntax ...
    > Can somebody help with a few lines *working* example?
    > Any idea appreciated!
    > Thanks
    > Rg.[/color]

    First you need to set up a little JavaScript to get the variable of the URL
    you're looking for (my JavaScript is a little rusty so I can't tell you the
    exact code to get it). Suppose you name the variable "url". So put this
    script in some page that the visitor will see:

    <script language="javas cript">
    url = (however you get the URL);
    document.write( "<img src='log.php?ur l=" + url + "' width='1'
    height='1'>" );
    </script>

    Then in log.php, use $_GET['url'] to access the URL and insert it into a
    database (or whatever you wanted to do with it).

    - JP


    Comment

    • chotiwallah

      #3
      Re: browser.history and log file

      "kingofkolt " <jessepNOSPAM@c omcast.net> wrote in message news:<5%MSc.247 246$IQ4.109595@ attbi_s02>...[color=blue]
      > "Rg" <spam@me.agai n> wrote in message
      > news:Xns95437C0 855428spammeaga in@195.131.52.1 35...[color=green]
      > > Hello,
      > > I am very beginner with PHP. I have an Apache PHP enabled
      > > webserver and want to know from where users are coming from.
      > > Understand I want the last surfer's browser visited url.
      > > I imagine I can do this with some kind of interraction
      > > between 2 scripts : one client side, one server side.
      > > The client one send the URL and the server one write it
      > > in the right log file.
      > > I have no idea of how to do this nor with principle nor
      > > with syntax ...
      > > Can somebody help with a few lines *working* example?
      > > Any idea appreciated!
      > > Thanks
      > > Rg.[/color]
      >
      > First you need to set up a little JavaScript to get the variable of the URL
      > you're looking for (my JavaScript is a little rusty so I can't tell you the
      > exact code to get it). Suppose you name the variable "url". So put this
      > script in some page that the visitor will see:
      >
      > <script language="javas cript">
      > url = (however you get the URL);
      > document.write( "<img src='log.php?ur l=" + url + "' width='1'
      > height='1'>" );
      > </script>
      >
      > Then in log.php, use $_GET['url'] to access the URL and insert it into a
      > database (or whatever you wanted to do with it).
      >
      > - JP[/color]

      2 solution without javascript

      (1) you can use $_SERVER['HTTP_REFERER']. that contains the previous
      url. note that not all browser sent this and that some browsers allow
      the user to fake it.

      (2) use a session in each of your pages to first read the previous url
      and then store the present url (which then becomes the previous url on
      the next page). this works obviuosly only if you want to monitor
      movement inside your site).

      you could also combine the 2 solution, i.e. use session if a previous
      url in the session is set and $_SERVER['HTTP_REFERER'] as fallback.

      micha

      Comment

      Working...