Req: Php Code to add refferring page URL to the contact form.

Discussion in 'PHP' started by kslokesh, Sep 17, 2009.

  1. #1
    I want to place the link to the PHP Contact form on the pages of my website and it should pass the URL of the page from which the contact form link is Clicked to an Input (either text box or Hidden) on the contact form along with other fields..

    Please tell me how to do that..

    can it be done by placing the code in the A HREF Link or by placing the code in contact form itself?

    Thank You..
     
    kslokesh, Sep 17, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <input type="hidden" name="referrer" value="<?php echo (isset($_SERVER['HTTP_REFERER']) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : ''); ?>" />
    Code (markup):
     
    premiumscripts, Sep 17, 2009 IP
  3. kslokesh

    kslokesh Well-Known Member

    Messages:
    153
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Thanks sir.. This uses the PHP code to retrieve Referrer from the HTTP header.. But will this work if the Browser is disabled to send referrer information to the next page?

    can any thing added to the A HREF link so that the referring URL is added to the Contact form field or into the contact form URL ?
     
    kslokesh, Sep 18, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Most people do not have referrers disabled, this should be a non-issue. You could ofcourse change your contact page href link to:

    <a href="contact.php?ref=<?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?>">contact</a>

    And then use that value in a hidden input field.
     
    premiumscripts, Sep 18, 2009 IP
  5. kslokesh

    kslokesh Well-Known Member

    Messages:
    153
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #5
    kslokesh, Sep 18, 2009 IP