php - 对远程服务器的curl授权不起作用

时间:2015-04-17 08:31:43

标签: php post curl http-post

请帮助,我现在花了3天时间来解决这个问题。 我尝试获得授权并在页面后显示" /index.php?page = xml",但我只获得登录页面,一些cookie保存到本地服务器。

这是PHP卷曲代码:

    <?php

$login = 'XX';
$password = 'XX';
$site = 'http://site';

$cookies = dirname(__FILE__) . '/cookies.txt';

$automatic = curl_init();

curl_setopt($automatic, CURLOPT_USERAGENT, $user_agent);
curl_setopt($automatic, CURLOPT_REFERER, "http://google.com/");
curl_setopt($automatic, CURLOPT_TIMEOUT, 10);

curl_setopt($automatic, CURLOPT_URL, $site . '/index.php?page=index');


curl_setopt($automatic, CURLOPT_RETURNTRANSFER, true);
curl_setopt($automatic, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($automatic, CURLOPT_POST, true);
curl_setopt($automatic, CURLOPT_POSTFIELDS, "user.auth.login=$login&user.auth.pass=$password");

curl_setopt($automatic, CURLOPT_COOKIEFILE, $cookies);
curl_setopt($automatic, CURLOPT_COOKIEJAR, $cookies);

curl_exec($automatic);

curl_setopt($automatic, CURLOPT_URL, $site. '/index.php?page=xml');
$demo = curl_exec($automatic);

curl_close($automatic);

echo $demo;
?>

cookie.txt的:

site FALSE  /   FALSE   1429273488  def.sess.number 2a86dcf7d2a896f323fb2931337efe60

网站表单:

<form name=enterform action="/index.php?page=index" method=post>
    <table border=0 cellspacing=0 cellpadding=2 width=740>
        <tr>

            <td valign=bottom bgcolor=#01568D width=80>
                <input type=input maxlength=32 size=9 class="logindata" name="user.auth.login" value="" onKeyDown="return TrapKeyDown(event);" onKeyPress="return TrapKeyPress(event);"><br>
                <input type=password maxlength=32 size=9 class="logindata" name="user.auth.pass" onKeyDown="return TrapKeyDown(event);" onKeyPress="return TrapKeyPress(event);">
            </td>
        </tr>
        <tr>
            <td bgcolor=#01568D height=40 colspan=2 align=right valign=bottom><a href="javascript:document.forms['enterform'].submit();"><font class="startbuttons">LOGIN</font></a>&nbsp;</td>
</tr>
    </table>
    </form>

Whagt我做错了吗?

0 个答案:

没有答案