0

我的报警公司有一个个人状态页面,我想以编程方式登录状态页面以获取一些状态,使用 PHP 和 cURL。

但是,登录表单使用 CSRF,所以我最初的想法是抓取站点,获取字段值,并使用 PHP 和 cURL 提交它们,并将 cookie 保存在 cookie 文件中。

据我了解,问题在于登录站点使用的是 Backbone,并且很多内容都是用 JavaScript 加载的。因此,每当我尝试获取数据时,我都会被重定向到“选择您的语言”页面,即使我设法登录。

我尝试登录的页面是https://mypages.verisure.com,这是我目前拥有的代码:

<?php

$username = 'xx@xx.xx';
$password = 'xx';
$loginUrl = 'https://mypages.verisure.com/j_spring_security_check?locale=no_NO';

// init curl
$ch = curl_init();

// set the url to work with
curl_setopt( $ch, CURLOPT_URL, $loginUrl );

// enable http post
curl_setopt( $ch, CURLOPT_POST, 1 );

// set the post parameters
curl_setopt( $ch, CURLOPT_POSTFIELDS, 'j_username=' . $username . '&j_password=' . $password . '&spring-security-redirect=%2Fno%2Fstart.html' );

// handle cookies for the login
curl_setopt( $ch, CURLOPT_COOKIEJAR, 'cookie.txt');

//Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
//not to print out the results of its query.
//Instead, it will return the results as a string return value
//from curl_exec() instead of the usual true/false.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );

// execute the request
$store = json_decode( curl_exec( $ch ) );

if ( $store->status == 'ok' )
{
    curl_setopt( $ch, CURLOPT_URL, 'https://mypages.verisure.com' . $store->redirectUrl );

    $content = curl_exec( $ch );

    var_dump( $content );
}

?>

$store变量包含以下内容:

{
    "status": "ok",
    "redirectUrl": "/no/start.html",
    "message": null
}

您对如何登录使用 SSL 和 JavaScript 的网站有任何提示吗?

4

1 回答 1

1

如果需要 JavaScript,cURL 和 PHP 可能不是合适的工具。您可以尝试使用 PhantomJS,它是一个基于 Webkit 的无头浏览器,即使涉及 JavaScript,也可用于自动与网站交互。

于 2014-12-07T10:17:26.087 回答