0

以下代码无法按我的预期工作......

curl_setopt($ch, CURLOPT_POSTFIELDS, "password="+$alphas[$x]+"&submit=yes");

通过将字母放入字符串中, $alphas[$x] 部分似乎不起作用。下面几行我回显 $alphas[$x] 并且效果很好。

例如,如果我将第一行代码更改为...

curl_setopt($ch, CURLOPT_POSTFIELDS, "password=j&submit=yes");

它可以按预期完美运行,因此我认为 $alpahs[$x] 没有像应有的那样将字母放入字符串中。

$content = "7";
$x = 0;
$alphas = array_merge(range("A", "Z"), range("a", "z"));

while($x < 52) {
print_r($alphas[$x]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL, "/Demo/form.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "password="+$alphas[$x]+"&submit=yes");
$content=curl_exec($ch);

echo $content;
echo "Pass: ";
echo $alphas[$x];
echo "<br>";
$x++;

}
4

2 回答 2

3

句点是字符串连接运算符,而不是加号:

curl_setopt($ch, CURLOPT_POSTFIELDS, "password=".$alphas[$x]."&submit=yes");
于 2012-11-19T23:12:45.347 回答
0

您还可以使用以下语法将变量插入双引号字符串:

curl_setopt($ch, CURLOPT_POSTFIELDS, "password={$alphas[$x]}&submit=yes");
于 2012-11-20T02:10:51.567 回答