<?php
$cookie_file = tempnam('./temp','cookie');
$login_url = 'http://bbs.php100.com/login.php';
$post_fields = 'cktime=31536000&step=2&pwuser=aaa&pwpwd=1111';$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
$a = curl_exec($ch);
//echo $a;
curl_close($ch);
$url='http://bbs.php100.com/profile.php?action=modify';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
echo $contents;
//preg_match('/<li>?????(.*)<\/li>/',$contents,$arr);
echo $arr[1];
curl_close($ch);
?>这段代码是用来登陆php100论坛的,我想问一下这个$post_fields是怎么确定的,怎么知道要穿过去的是什么内容
$cookie_file = tempnam('./temp','cookie');
$login_url = 'http://bbs.php100.com/login.php';
$post_fields = 'cktime=31536000&step=2&pwuser=aaa&pwpwd=1111';$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
$a = curl_exec($ch);
//echo $a;
curl_close($ch);
$url='http://bbs.php100.com/profile.php?action=modify';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
echo $contents;
//preg_match('/<li>?????(.*)<\/li>/',$contents,$arr);
echo $arr[1];
curl_close($ch);
?>这段代码是用来登陆php100论坛的,我想问一下这个$post_fields是怎么确定的,怎么知道要穿过去的是什么内容
<form action="login.php?" method="post" name="login">
<select name="lgt" onchange="document.login.pwuser.focus();" class="f14">
<option value="0" SELECTED>用户名</option>
<option value="1" >UID</option>
</select>
<input class="input" type="text" tabindex="11" name="pwuser" />
密 码
<input class="input" type="password" tabindex="12" name="pwpwd" /> 隐身登录
<input name="hideid" type="radio" value="1" />开启
<input name="hideid" type="radio" value="0" checked tabindex="18" />关闭
<button type="submit" tabindex="19">登录</button>
<input type="hidden" name="forward" value="" />
<input type="hidden" name="jumpurl" value="http://bbs.php100.com/profile.php?action=modify" />
<input type="hidden" name="m" value="bbs" />
<input type="hidden" name="step" value="2" />
<input type="hidden" name="cktime" value="31536000" />
</form>
凡是有 name 属性的表单元素,都应该是属于 $post_fields 中的内容
查看一下登录页面的表单需要传的值有哪些
至于部分值不用传 你可以自己试着去掉一些不必要的 总之全传过去是可以的