简体   繁体   English

将外部页面加载到PHP模板中

[英]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. 尝试将Google Analytics(分析)页面加载到我的一个PHP模板中,以便保留导航标题。

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: 我想我将创建一个名为“ analytics”的页面,并首先包含我的导航标题页面,然后在其下面放置一个PHP页面include:

<?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. 那没有用,所以我创建了第三个页面,其中包含了file_get_contents代码,然后为其中包含该代码的页面创建了一个include。 In both cases, the links go directly to Google and my template is dismissed. 在这两种情况下,链接都直接转到Google,而我的模板被关闭了。 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. 在您的analytics.php中加载您的页眉和页脚,并将其置于两者之间-无需包含此类内容。 (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解析出来

    $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]; 将其拆分为您选择的单词出现的位置,然后页面的其余部分将在$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. 然后,您可以算出您混搭了html的哪些位,并在剥离内容之前和之后回显了这些内容。

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 如果重定向到登录页面,表明他们的页面未接受您在查询字符串中提供的登录凭据,则可能对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." 内容为:“如果用户尚未登录,则Google会提示用户登录。然后Google显示授权页面,该页面允许用户查看您的应用程序请求访问的Google服务数据。” 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. 可能还有https://developers.google.com/identity/protocols/OAuth2,但这超出了我的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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