www.webdeveloper.com
Results 1 to 10 of 10

Thread: URL Refer Link Help

  1. #1
    Join Date
    Dec 2008
    Posts
    126

    URL Refer Link Help

    Hi, I have a page that allows user to click on a form and send the url of the visited page to themselves (e.g. visit page1.php - click on form on page1.php get to form fill some info and send the email to themselve). I am using $_SERVER['HTTP_REFERER'] in the form to get the url of page1.php in the email. But it is not working. I only get http:///// instead. Is there a better way to send refer url to email? I am using phpmailer.

    Thanks,
    mandy.

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    558
    Very confusing post.

    You say: "visit page1.php - click on form on page1.php get to form". What do you mean "get to form"?

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    The referer header is never guaranteed to be sent by the browser, so you should not depend on it.

    I would probably try to build it into the form itself, perhaps as a hidden field.
    PHP Code:
    <input type='hidden' name='referer' value='<?php
    echo htmlspecialchars($_SERVER['PHP_SELF']);
    ?>' />
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Dec 2008
    Posts
    126
    ginerjm: page1.php has a link to a form. When the link is clicked it will take the user to the form. I am using the $_SERVER['HTTP_REFERER'] to get the page1.php to the form and email to the user.

    NogDog: $_SERVER['PHP_SELF'] will only give me the url of the form. I don't want the form url I want the url of the page visited prior to the form (e.g. page1.php).

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Oh, sorry. In that case, unless you have control over that referring page and can create a cookie or something to track activity, there is no way to be sure where they came from, since the referer header could be turned off for privacy reasons, or maybe they're coming through a proxy, or someone just gave them your URL and the called the page directly, and so forth. In other words, you're pretty much stuck with HTTP_REFERER, and you have to simply cope with the fact that sometime it will be empty (and conceivably could even be a faked/spoofed value) -- again, assuming you have no control over the referring pages.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    558
    Aha! Now you're a little bit clearer. So you go from page1 to a new page that has a form and you want to save calling page (page1) to use to email the user once he completes this form?

    How do you use a url (http_referer) to send an email?

  7. #7
    Join Date
    Dec 2008
    Posts
    126
    Nogdog: I do have access to the referring page I tried to put $_SESSION['refurl'] = $_SERVER['PHP_SELF']; in the referring page and pass it to the form but still not getting the link.

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Did you put a session_start() on both the referring page and the form page before you try to access $_SESSION?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  9. #9
    Join Date
    Dec 2008
    Posts
    126
    yes. I am getting other data saved in the cookies just not the link

  10. #10
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    558
    You're saying that a session var you created in 'page1' is not found in the next page? Either you didn't spell it correctly, didn't use the exact same capitalization, or didn't start your session before accessing the session array in one of the pages

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