duanran3115 2015-06-26 23:07
浏览 51

获取页面内容,就像用户打开一样

I'm trying to get some of IPBoard registry data by using external site since 777 chmoding on whole forum registry would be a terrible idea. Registry returns user data for user if he's logged in on forums. I've created a page which initiates the registry and prints the data. Loading the registry and getting the data to page is quite simple

//userQuery.php
<?php
define("ALLOW_FURLS", false);
require_once 'forum/initdata.php';
require_once IPS_ROOT_PATH . 'sources/base/ipsRegistry.php';
$registry = ipsRegistry::instance();
$registry->init();

$member = $registry->member()->fetchMemberData();
$data = json_encode($member);

print $data;
?>

and if opened by user works perfectly. Problems started when I tried accessing my userQuery.php through external site as intended. Both curl and fopen from external site acts as requested by server not user visiting the site and returns Guest data since server is not logged in.

So doing

<?php
$url = "http://foo.bar/userQuery.php";
$handle = fopen($url, "r");
$result = fread($handle, 8192);

var_dump($result);
?>

Returns server memberdata which is Guest, instead of user memberdata as userQuery would if accessed normally by opening it in a browser.

Is there a way to open that page (userQuery.php) as if user requested its content using php or js as the last resort? I'm not looking forward to rewriting IPBoard registry just to provide external access checks with the forums.

  • 写回答

1条回答 默认 最新

  • dsds33222 2015-06-27 02:14
    关注

    I am assuming you want this to happen as your users visit the site right? So, when Bob shows up on the site and logs in, you get his data. And later, when Lucy logs in, you get her data.

    If that assumption is right, you could put a little script on your site that would post data back to your server via an AJAX call.

    Your userQuery.php would look like the following (if you use jQuery for the AJAX call) and you'd need to include it in one of the pages on your site so it gets loaded when users visit the site.

    //userQuery.php
    <?php
    define("ALLOW_FURLS", false);
    require_once 'forum/initdata.php';
    require_once IPS_ROOT_PATH . 'sources/base/ipsRegistry.php';
    $registry = ipsRegistry::instance();
    $registry->init();
    
    $member = $registry->member()->fetchMemberData();
    $data = json_encode($member);
    
    echo "<script>var data = {$data}; $.post('/some/url/on/your/site/receiver.php', data);</script>";
    ?>
    

    Then you'd need to have a script at /some/url/on/your/site/receiver.php that grabs the data out of $_['POST'] and does something with it.

    Or, I'm totally misinterpreting what you want and you can ignore this answer. :)

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探