首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在cURL中使用PHP创建多个帖子

在cURL中使用PHP创建多个帖子
EN

Stack Overflow用户
提问于 2013-05-27 22:21:58
回答 2查看 2.3K关注 0票数 0

我正在尝试使用PHP中的cURL登录我的Elance帐户。我通过第一个登录表单成功登录。但是,您必须在下一页回答安全问题。我正在尝试发布答案并提交表单,但是,我无法让它发布并提交表单。我试图在1个.php文件中做到这一点。第二篇文章是否需要在单独的文件中完成,还是可以在同一文件中完成?下面是我的代码:

代码语言:javascript
复制
<?php

$username = 'Blah';
$password = 'BlahBlah';
$useragent = $_SERVER["HTTP_USER_AGENT"];
$postdata="lnm=$username&pwd=$password";
$postdata_2 = "challengeAnswer=Secret";

$ch = curl_init();

//Main Login
curl_setopt ($ch, CURLOPT_URL,"https://www.elance.com/php/landing/main/login.php");
curl_setopt ($ch, CURLOPT_HEADER, true);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt ($ch, CURLOPT_REFERER, "https://www.elance.com/php/landing/main/login.php");
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);



//Security Question
curl_setopt($ch, CURLOPT_URL, "https://www.elance.com/php/trust/main/securityAudit.php?timestamp=1369701194&userid=4312662&saamode=NCR&hash=b5523cd532c401e374c8a06e6d2fbfa39ac82387&ncr_persisid=643029635&kmsi=&redirect=https%3A%2F%2Fwww.elance.com%2Fphp%2Fmyelance%2Fmain%2Findex.php%3Fredirect%3Dhttps%253A%252F%252Fwww.elance.com%252Fmyelance");
curl_setopt ($ch, CURLOPT_HEADER, true);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt ($ch, CURLOPT_REFERER, "https://www.elance.com/php/trust/main/securityAudit.php?timestamp=1369701194&userid=4312662&saamode=NCR&hash=b5523cd532c401e374c8a06e6d2fbfa39ac82387&ncr_persisid=643029635&kmsi=&redirect=https%3A%2F%2Fwww.elance.com%2Fphp%2Fmyelance%2Fmain%2Findex.php%3Fredirect%3Dhttps%253A%252F%252Fwww.elance.com%252Fmyelance");
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata_2);
curl_setopt ($ch, CURLOPT_POST, 1);

$result_2 = curl_exec($ch);

echo $result_2;

curl_close($ch);

?>

我尝试了几种不同的方法,但似乎都不起作用。我需要你帮我做第二站指挥部。

EN

回答 2

Stack Overflow用户

发布于 2013-05-27 22:32:39

我可以在第二个cURL的参数上看到时间戳和散列

代码语言:javascript
复制
curl_setopt($ch, CURLOPT_URL, "https://www.elance.com/php/trust/main/securityAudit.php?timestamp=1369701194&userid=4312662&saamode=NCR&hash=b5523cd532c401e374c8a06e6d2fbfa39ac82387&ncr_persisid=643029635&kmsi=&redirect=https%3A%2F%2Fwww.elance.com%2Fphp%2Fmyelance%2Fmain%2Findex.php%3Fredirect%3Dhttps%253A%252F%252Fwww.elance.com%252Fmyelance");

这意味着,对于您尝试从第一个cURL发出的每个请求,都会创建一个新的唯一cURL,并且该URL将是使用第二个url尝试发布的唯一有效url。你不能简单地将第二个“安全问题”页面的url复制并粘贴到你的第二个cURL上,因为每次都会有其他的时间戳和/或哈希。

你不能仅仅用时间戳/散列来硬编码一个url。它将从该站点的服务器中丢弃。您需要以某种方式动态获取该url并在您的第二篇文章中使用它。

此外,还可能有一个"http referer“检查。

票数 0
EN

Stack Overflow用户

发布于 2013-05-27 22:35:48

代码语言:javascript
复制
if( $curl = curl_init() ) {
    curl_setopt($curl, CURLOPT_URL, 'http://your-domain.com/file.php');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, "text=test");
    $out = curl_exec($curl);
    echo $out;
    curl_close($curl);
  }

然后你可以通过$_POST‘text’获得http://your-domain.com/file.php中的文本变量;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16775229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档