CURL用旋转键提交表单 [英] CURL to submit form with rotating key

查看:162
本文介绍了CURL用旋转键提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我自己的网站上创建一个自动脚本,它登录到网站,传递一些POST头,并基本上开始导出。

I'm attempting to create an automated script on my own site which logs into the site, passes some POST Headers and essentially starts an export.

由于每个网页载入时都有不同的旋转键,因此难以通过登录页面。

However, I am having difficulty getting passed the login page since there is a rotating key that is different on every page load.

我试图运行脚本没有可用,脚本如下在顶部输出$ xid。但是如果我检查$ xid回应它不同于当前的页面上的xid值。

I have tried running the script with no avail, the script below outputs the $xid at the top. But if I check the $xid echoed it is not the same as the current xid value on the page.

编辑:好问题Norman - 这只是你简单的隐藏字段每次重新加载页面时都会更改的随机值。所以基本上看来我必须找到一个页面的xid之前的'curl_exec'ing它,我不知道如何做,或者如果它甚至可能。也许这需要一些JS和CURL。

Good question Norman - It's just your simple hidden field with a random value that changes every time the page is reloaded. So basically it seems I have to find the xid of a page before 'curl_exec'-ing it which I don't know how to do or if it's even possible. Maybe this requires some JS along with CURL.

Edit2:这是演示的示例网址

有关如何解决这个问题的任何想法?

Any ideas as to how to get around this?

<?php
set_time_limit(0);

# Begin Header info
$url = "https://secure.mywebsite.com/admin/import.php?mode=export";
$post = "mode=export&data%5yaddayaddayadda";
$agent = 'User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008100922 Ubuntu/8.04 (hardy) Firefox/3.0.3';
# End Header Info

# Begin Processing Info
$ch = curl_init($url);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
//curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie.txt'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec ($ch);
curl_close ($ch);
# End Processing Info


# Begin finding xID
$regex = '/name=\"xid\" value=\".*?\"/';
preg_match_all($regex,$content,$match);
$xid = substr($match[0][0], 18, -1);
echo $xid;
# End finding xID

    # Begin Header info
    $url = "http://secure.mywebsite.com/admin/";
    $post = "username=myusernamehere&password=mypasswordhere&mode=login&usertype=P&xid=".$xid."&redirect=admin";
    $agent = 'User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008100922 Ubuntu/8.04 (hardy) Firefox/3.0.3';
    # End Header Info

    # Begin Processing Info
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie.txt'); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    $content = curl_exec ($ch);
    curl_close ($ch);
    # End Processing Info


# Begin connection to export file
$url = "https://secure.mywebsite.com/admin/import.php?mode=export";
$post = "mode=export&data%5yaddayaddayadda";
# End connection to export file

# Begin Export
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie.txt'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec ($ch);
echo curl_exec($ch);
curl_close ($ch);
# End export

?>


推荐答案

第一个请求

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie.txt'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec ($ch);
curl_close ($ch);

第二个要求:

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie.txt');  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec ($ch);
curl_close ($ch);

这篇关于CURL用旋转键提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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