简体   繁体   English

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

[英]Extracting content from external website with authentication.

I'm currently trying to create a php script were the user has the ability to connect their user to several pages.如果用户能够将他们的用户连接到多个页面,我目前正在尝试创建一个 php 脚本。

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.我想要做的是检查用户是否登录到battlelog ,然后获取他的用户名。

I'm not sure if it's even possible... But i would appreciate any help I can get!我不确定这是否可能......但我会很感激我能得到的任何帮助!

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.您将在这里遇到的主要问题是,大多数现代浏览器都采用跨域安全机制来确保其他网站或潜在恶意网站无法非法访问其他浏览器中的用户数据 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.例如,如果 battlelog 公开了一个 API 供其他开发人员访问用户数据。

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.这当然会涉及服务器端跨域请求,因此您要么需要将服务器用作代理,要么使用 JSONP web 服务,其中响应以 JSON 格式发送,包含在回调 function 中。

Accessing Data From PHP Scripts:从 PHP 脚本访问数据:

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.由于您使用的是 PHP,因此您需要访问 API。PHP 脚本无法向浏览器发出请求,因此 battlelog 需要有一个插件架构,您可以在其中嵌入脚本到他们的网站,或者他们需要公开一个 API 供您从服务器查询。

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;
}

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

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