普通的表单登陆怎么修改成php curl模拟表单登陆
<form method="post" action="2.php"><br /> 用户名: <input type='text' name="loginname"><br><br /> 密码:<input type="password" name='loginpass'><br><br /> <input type='submit' value="submit"><br /></form>
header('Content-Type:text/html;Charset=utf-8');<br />if ($_POST['loginname'] == 'lee' && $_POST['loginpass'] == '123456') {<br /> header('location:http://bbs.csdn.net');<br />} else {<br /> <br />}
header('Content-type:text/html;Charset=utf-8'); <br />$user = 'lee'; //登陆用户名 <br />$pass = '123456'; //登陆密码 <br />$post_fields = "loginname={$user}&loginpass={$pass}";<br />$ch = curl_init(); <br />curl_setopt($ch,CURLOPT_URL,'http://localhost/2.php');<br />curl_setopt($ch,CURLOPT_POST,1);<br />curl_setopt($ch,CURLOPT_POSTFIELDS,$post_fields);<br />curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); <br />curl_exec($ch);<br />curl_close($ch);