SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting a javascript value from PHP?

    I've got a popup window that I need the referer for. Apache's HTTP_REFERER is blank because the popup is a Javascript child window and not really a page (or something like that).

    Anyway, I'm able to get the referrer via "opener.location.href" in Javascript, but I'd like to transfer it over to the PHP space so I can use it in my PHP script.

    I thought of assigning the variable to a hidden form field, but then the page would have to be reloaded for PHP to see it.

    Any other ideas? Thanks.

  2. #2
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    perhaps you could pass that referer along with the popup code.


    ie


    popupwin("popupstuff.php3?<? echo("$http_refer"); ?>"




    or whatever the correct code would be.
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  3. #3
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Milamber - I though of that, but my situation is complex and that would be cumbersome.


    Some Javascript guru must know how to do this?

  4. #4
    SitePoint Enthusiast nguip's Avatar
    Join Date
    Apr 2001
    Location
    Malaysia
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm interested in this topic as well...
    Ngu I.P.
    Web Developer

  5. #5
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A client side technology cannot communicate with a server side technology without an HTTP request.

    I wanted to do something like this once too. I wanted to insert the parent window href into a form field. The easiest way is to have php print it out, but as you said there isn't a referer when using a javascript window.open. So I made a javascript function that printing that value into the forum.

    I suggest you look for a javascript method to do what you wanted PHP to do, lacking that you'll have to make another http request to send that information to php.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  6. #6
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I too needed it in a form. I figured out a kludgy way of fixing my problem.


    In the form I displayed it as plain text (not in a entry field) with

    Code:
    <script>JAVASCRIPT: window.document.write(opener.location.href);</script>
    Then it was passed to the form handling script via a hidden field.

    Code:
    <form name="feedbackform" method="post" action="$PHP_SELF"  onSubmit="document.feedbackform.refer.value=opener.location.href">
    <INPUT TYPE="hidden" NAME="refer">
    So this displays the referrer on the form before it's submitted, and then puts the referrer into $refer variable when it's submitted.

  7. #7
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about passing the values to a cookie? (readable by both Javascript and PHP)


  8. #8
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aha. Time to read the cookies chapters in my PHP book.


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
  •