duannengling4705
2012-04-07 23:33
浏览 41
已采纳

通过身份验证从外部网站提取内容。

I'm currently trying to create a php script were the user has the ability to connect their user to several pages.

That was the idea.

What i'm trying to to is to check if the user is logged in to battlelog, and then grab his username.

I'm not sure if it's even possible... But i would appreciate any help I can get!

图片转代码服务由CSDN问答提供 功能建议

我正在尝试创建一个php脚本,用户可以将用户连接到多个页面。

这就是主意。

我要做的是检查用户是否已登录 battlelog ,然后抓住他的用户名。

我不确定它是否可能...... 但我希望得到任何帮助!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duandingyou3331 2012-04-07 23:38
    已采纳

    The main problem you're going to run into here is that most modern browsers employ cross-domain security to make sure that other websites or potentially malicious websites cannot gain illegal access to the user data in another browser window.

    What you're hoping to accomplish is what's called cross-site scripting. It is possible under certain circumstances. For instance, if battlelog exposes an API for another developer to access user data.

    This would of course involve server-side requests cross-domain, so you'd either need to use your server as a proxy, or use a JSONP web service where the response is sent in JSON format wrapped in a callback function.

    Accessing Data From PHP Scripts:

    Since you're using PHP, you'd need to have access to an API. PHP scripts cannot make requests to a browser, so battlelog would either need to have a plug-in architecture where you can embed scripts in their website, or they would need to expose an API for you to query from your server.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dtwvr26066 2012-04-23 18:31

    I created this script, and i hope someone will find use of it.

    $data = array( 
    
    'redirect' => '', 
    
    'email' => $email, 
    
    'password' => $password ,
    
    'submit' => 'Sign+in'
    
    ); 
    
    $cr = curl_init('http://battlelog.battlefield.com/bf3/gate/login/'); 
    
    curl_setopt($cr, CURLOPT_RETURNTRANSFER, true);
    
    curl_setopt($cr, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    
    curl_setopt($cr, CURLOPT_COOKIEJAR, 'cookie.txt');
    
    curl_setopt($cr, CURLOPT_POST, true);
    
    curl_setopt($cr, CURLOPT_POSTFIELDS, $data);
    
    $output = curl_exec($cr);
    
    echo $output;
    
    curl_close($cr);
    
    
    $cr = curl_init('http://battlelog.battlefield.com/bf3/'); 
    
    curl_setopt($cr, CURLOPT_RETURNTRANSFER, true);
    
    curl_setopt($cr, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    
    curl_setopt($cr, CURLOPT_COOKIEFILE, 'cookie.txt');
    
    $output = curl_exec($cr); 
    
    curl_close($cr); 
    
    
    include '/scripts/shd/simple_html_dom.php';
    
    $html = new simple_html_dom();
    
    $html -> load($output);
    
    foreach($html->find('#base-user-name a') as $e)
    {
        $battlelog_username = $e->plaintext;
    }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题