Home Backend Development PHP Tutorial 普通的表单登陆如何修改成php curl模拟表单登陆

普通的表单登陆如何修改成php curl模拟表单登陆

Jun 13, 2016 am 11:49 AM
curl gt http lt nbsp

普通的表单登陆怎么修改成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>
Copy after login


2.php
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 />} 
Copy after login

请教一下这样的表单怎么修改成模拟登陆 我是这样写的为什么不对呢
新建一个1.php
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);
Copy after login

------解决方案--------------------
echo curl_exec($ch); 

另外你的2.php是跳转了,并没有返回内容。
改成echo file_get_contnets('location:http://bbs.csdn.net'); 试试
------解决方案--------------------
header('location:http://bbs.csdn.net');
形成的 http 头
HTTP/1.1 302 Found
Date: Wed, 26 Feb 2014 09:16:38 GMT
location: http://bbs.csdn.net
Content-Length: 0
Content-Type: text/html;Charset=utf-8

你不跟着跳转吗?
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
------解决方案--------------------
#1 不是说了吗?
echo curl_exec($ch);
你不输出结果怎么能行?

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  


    <script></script>



    
    CSDN论坛首页 - CSDN.NET
    <script></script>
    <script><br /> $(function() {<br /> main_page_js.index_page();<br /> });<br /> </script>
    


  
  
    
    
  
   <br>    <br>    <br>  

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

Solution: Your organization requires you to change your PIN

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

What are the differences between Huawei GT3 Pro and GT4?

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

10 Ways to Adjust Brightness on Windows 11

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

How to turn off private browsing authentication for iPhone in Safari?

What does http status code 520 mean? What does http status code 520 mean? Oct 13, 2023 pm 03:11 PM

What does http status code 520 mean?

Tutorial on updating curl version under Linux! Tutorial on updating curl version under Linux! Mar 07, 2024 am 08:30 AM

Tutorial on updating curl version under Linux!

Win10/11 digital activation script MAS version 2.2 re-supports digital activation Win10/11 digital activation script MAS version 2.2 re-supports digital activation Oct 16, 2023 am 08:13 AM

Win10/11 digital activation script MAS version 2.2 re-supports digital activation

Understand common application scenarios of web page redirection and understand the HTTP 301 status code Understand common application scenarios of web page redirection and understand the HTTP 301 status code Feb 18, 2024 pm 08:41 PM

Understand common application scenarios of web page redirection and understand the HTTP 301 status code

See all articles