Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting another URL's Javascript variable in PHP?

    I was wondering if there was some way to get a javascript variable from another url into a variable within PHP?

    For example:

    A page called http://www.exampleurl.com/page (which I do not have control over) with some inline javascript like:

    Code:
    function examplefunction() {
            evar = "http://aurl.com";
        }
    Assuming there's HTML and other javascript surrounding this variable I want, how would I be able to retrieve it? Is there a special function to do this, or would it be easier to simply parse the HTML through PHP and then trim the variable to what I want?

    In theory, the PHP would have a URL set to retrieve the JS from, and it would echo only what is in that variable.

    PHP code (hypothetical) at mysite.com/getvariable.php:

    PHP Code:
    $url 'exampleurl.com/page';
        
    $js_var =  get_js_data($url$evar);
        echo 
    $js_var
    Thanks in advance to anyone who can help me out here!
    Last edited by Fou-Lu; 08-31-2013 at 12:29 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    PHP cannot be used to detect the current state of a JS variable. It can hypothetically be used to determine the initial state of such a variable; it is simply a matter of parsing the text provided as a return result and searching for the variable.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Tags for this Thread

    Posting Permissions

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