Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: getting HTTP_REFERRER to a form

  1. #1
    Join Date
    Feb 2006
    Posts
    6

    Angry getting HTTP_REFERRER to a form

    I want my form to send me the referring page to the form. I have the form listed on multiple pages, and would like to know where the user came to the form from. The standard function in formmail only tells me the from url.

    I have started with this code below but its not working. Jus was a try. Any ideas?

    <head>

    <SCRIPT language = JavaScript>

    function getref() {
    var ref = document.referrer
    document.JOIN.website.value = ref
    }

    </SCRIPT>

    </head>

    <body>
    <form name="JOIN" method="post" action="/form.php">

    <input type="hidden" name="website" value="" />

    <input type="hidden" name="calc" value="none" onLoad = getref()/>

    ( form continues )

  2. #2
    Join Date
    Mar 2004
    Posts
    2,224

    Default Re: getting HTTP_REFERRER to a form

    using PHP is easier than using Javascript for this.

    Here's what to do:
    1. rename your form from .html to .php: myform.html become myform.php.
    2. open it in your browser with the new name - you can see it works the same
    3. add in a hidden field and set it to the referer, like this
      PHP Code:
      <input type="hidden" name="urltoform" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />
      note the correct (bug wrong!) spelling of HTTP_REFERER.
    4. remove your javascript code

  3. #3
    Join Date
    Feb 2006
    Posts
    6

    Default Re: getting HTTP_REFERRER to a form

    Thanks!!!!! Saved me a headache i tried php first but my form didnt like the way i did.

  4. #4
    Join Date
    Feb 2006
    Posts
    6

    Default Re: getting HTTP_REFERRER to a form

    I have another quick question for you.

    I have different directories say mydomain.com/help/ or mydomain.com/info/ how can i isolate that directory into its own form variable for the url variable?

    for example make a hidden field called "directory" and have it directory=help in this instance and then create a thrid variable that says

    if directory=help
    then title=Help Department
    if directory= info
    then title= Info Section
    else title=Main

    I really need to learn PHP myself

    Thanks again,

    Steve

  5. #5
    Join Date
    Feb 2006
    Posts
    6

    Default Re: getting HTTP_REFERRER to a form

    I managed to figure out getting the url. However I dont know how to take the directory off of the end to store to a variable and exclude the forward slashed or use them as "guides" to find the correct variable.

    If url= http://www.mydomain.com/help/

    i want to set dir = Help
    (with the capital H, but i believe thats just the ucwords fuction)

    Have any ideas?

  6. #6
    Join Date
    Feb 2006
    Posts
    6

    Default Re: getting HTTP_REFERRER to a form

    i have it working with the else statement manually, but i would like it to do it by itself.

  7. #7
    Join Date
    Jan 2007
    Posts
    8

    Default Re: getting HTTP_REFERRER to a form

    Hi. I have my form up and running and have managed to get the http_referer working, BUT it only tells me the page that was used to refer to the form. (since I only have one form page I already know that!)

    Is there any way of getting information about where the user came from before they came to my site? It would be very useful to know how they found my page for marketing purposes. I get daily stats from my ISP that has similar data so Im assuming it must be capturable somehow.

    Cheers,
    Dave.

  8. #8
    Join Date
    Mar 2004
    Posts
    2,224

    Default Re: getting HTTP_REFERRER to a form

    yep, my answer above explains it.

  9. #9
    Join Date
    Jan 2007
    Posts
    8

    Default Re: getting HTTP_REFERRER to a form

    Thanks, but I must be missing something. I have copied and pasted your text above into my html form page, but the results I get back are exactly like this:

    urltoform: <?php echo $_SERVER['HTTP_REFERER']; ?>

    Are there brackets in the wrong place or something?

  10. #10
    Join Date
    Jan 2007
    Posts
    8

    Default Re: getting HTTP_REFERRER to a form

    OK, Im moving forwards...
    So I figured that you meant for the actual forms page to be renamed as .php rather than just the script. Ive dont that now and getting the 'desired' results.

    However Im still not really getting the info that I need. I'll explain:
    The above method will only display the referring page which is within 1 page of the form that is submitted. This is fine if the referring link points directly to your form AND the user then fills in the form straight away without browsing the rest of your site. So in reality you only get the internal reffering page from your own site. (the last page they were on before sending the form) Its to be expected (Id say my situation is very normal) that a user would come to my site from another, have a browse around my site to see what I sell, then decide to find the form page and send off a message.

    Is there any way that I can capture the initial (external) referring site regardless of how many pages they view within my site?

    Dave.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •