简体   繁体   中英

Load external page into PHP template

Trying to load a Google Analytics page into one of my PHP templates so I can keep the navigation header.

I figured I would create a page called "analytics" and include my navigation header page first, then put a PHP page include right under it:

<?php include'navigation.php'; ?>
<?php print file_get_contents("https://analytics.google.com/analytics/web/?et&authuser=0#realtime/rt-overview/*MY_ID_INFO*/")?>

That didn't work, so I created a third page that housed the file_get_contents code, then just created an include for the page with that code on it. In both cases, the links go directly to Google and my template is dismissed. Is there any way to include the page from within my template?

我只会使用iFrame代替。

In your analytics.php load your header and footer and put this in between - no include as such. (Probably a million and one security vulnerabilities to consider though).

    <?php
    $handle = fopen("https://analytics.google.com/analytics/web/?et&authuser=0#realtime/rt-overview/*MY_ID_INFO*/", "r");
    $contents = stream_get_contents($handle);
    echo $contents;
    ?>

This got me the content of a different webpage which I was able to parse to get the bits I wanted.

If you can find out on the page itself whether there is a header redirect on the page itself which causes the redirection, you might be able to parse that out from $content

    $content = array();
    $content = explode( "somewords", $content );

to split it where the words you select appear then the rest of the page will be in $content[1];

You would need to split that again in the same way to remove their footer. Then you could work out which bits of html you had mashed and echo those before and after your stripped down content.

If it is redirecting to a login page that suggests that their page has not accepted the login credentials you are offering in your query string - perhaps this might help https://developers.google.com/gdata/docs/auth/overview

Which says: "If the user is not already logged in, Google prompts the user to log in. Google then displays an authorization page that allows the user to see what Google service data your application is requesting access to." which seems to be happening, so it is perhaps not happy with the string.

and possibly https://developers.google.com/identity/protocols/OAuth2 but it is beyond what I can advise on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM