以编程方式登录到SSL站点卷曲和PHP [英] Programmatically log in to SSL site with cURL and PHP

查看:215
本文介绍了以编程方式登录到SSL站点卷曲和PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My alarm company has a personal status page for me, and I want to programmatically log in to the status page to fetch some statuses, using PHP and cURL.

然而,登录表单使用CSRF,所以我最初的想法是刮的部位,获取字段值,并与PHP和卷曲提交他们,并保存cookies在一个cookie文件。

However, the login form uses CSRF, so my initial idea was to scrape the site, getting field values, and submitting them with PHP and cURL, and saving the cookies in a cookie file.

据我了解,问题是,在登录网站使用中坚力量,很多内容加载的JavaScript。所以,每当我试图获取数据,我重定向到选择你的langauge页,即使我设法登录。

The problem as I understand it, is that the login site is using Backbone, and much content is loaded with JavaScript. So whenever I try to fetch data, I get redirected to the "Select your langauge" page, even if I manage to log in.

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

The page I try to log in at is https://mypages.verisure.com, and this is the code I currently have:

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

?>

$商店变量包含以下内容:

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

你对如何登录上使用SSL和JavaScript网站任何提示。

Do you have any tips on how to log in on a site that uses SSL and JavaScript.

推荐答案

卷曲和PHP也有可能不是正确的工具,如果需要的JavaScript。您可以尝试 PhantomJS 相反,这是一个无头的Webkit基于浏览器,并可以用来与网站即使自动交互的JavaScript参与。

cURL and PHP are probably not the right tools if JavaScript is needed. You might try PhantomJS instead, which is a headless Webkit based browser and can be used to automate interaction with web sites even if JavaScript is involved.

这篇关于以编程方式登录到SSL站点卷曲和PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆