www.webdeveloper.com
Results 1 to 6 of 6

Thread: Referral Source & Hidden Fields

  1. #1
    Join Date
    Jan 2007
    Posts
    26

    Referral Source & Hidden Fields

    Hi,

    Does anyone know if it's possible to capture the visitors source from Google Analytics and pass that through a form using a hidden field? Here is what I am looking to do. I have a form on my website that I'd like to know where that specific person who filled out the form came from. Can you help me with this?

  2. #2
    Join Date
    Oct 2013
    Location
    3rd planet from the sun
    Posts
    163
    Code:
        <input id="ip" name="ip" value="<?php echo ($_SERVER 'REMOTE_ADDR']); ?>" type="hidden">
        <input id="host" name="host" value="<?php $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']); echo ($hostname); ?>" type="hidden">
    This will capture your visitor's IP address in the form...no need for Google Analytics.

  3. #3
    Join Date
    May 2014
    Posts
    807
    @kralcx, since it would exist anyways in PHP, why bother passing it into an input in the first place?
    Java is to JavaScript as Ham is to Hamburger.

  4. #4
    Join Date
    Oct 2013
    Location
    3rd planet from the sun
    Posts
    163
    Quote Originally Posted by deathshadow View Post
    @kralcx, since it would exist anyways in PHP, why bother passing it into an input in the first place?
    Doesn't it need to be passed into an input so that the ip address will be emailed along with the rest of the form?

  5. #5
    Join Date
    Mar 2011
    Posts
    1,137
    He doesn't want the IP Address. He wants the referrer, as in $_SERVER['HTTP_REFERER'].
    Rick Trethewey
    Rainbo Design

  6. #6
    Join Date
    May 2014
    Posts
    807
    Quote Originally Posted by kralcx View Post
    Doesn't it need to be passed into an input so that the ip address will be emailed along with the rest of the form?
    ... and how exactly would the value in $_SERVER['REMOTE_ADDR'] change between sending the form and receiving the form? That value would be the same. In fact if it changes, it's either not the same user, or someone's faking IP addy's for MITM attacks.

    Quote Originally Posted by rtrethewey View Post
    He doesn't want the IP Address. He wants the referrer, as in $_SERVER['HTTP_REFERER'].
    That value on the other hand would change -- though I STILL wouldn't send it as part of the form, I'd set it as a $_SESSION value.

    Code:
    session_start();
    session_regenerate_id();
    if (!isset($_SESSION['originatedFrom'])) {
      $_SESSION['originatedFrom'] = $_SERVER['HTTP_REFERER'];
    }
    Would keep track of where the user for this session came from. Put that wherever you start your session (or add it to the start of the code if you aren't running sessions), and use $_SESSION['originatedFrom'] wherever you want that value.
    Last edited by deathshadow; 06-29-2014 at 12:39 PM.
    Java is to JavaScript as Ham is to Hamburger.

Thread Information

Users Browsing this Thread

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

Posting Permissions

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



Recent Articles