Hello and welcome to our community! Is this your first visit?
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
    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:

    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);
    Thanks in advance to anyone who can help me out here!
    Last edited by Fou-Lu; 08-31-2013 at 01:29 PM.

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 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