How to change a common form login to a phpcurl simulated form login

Source: Internet
Author: User
How to change a common form login to a phpcurl simulated form login
 


2. php
header('Content-Type:text/html;Charset=utf-8');if ($_POST['loginname'] == 'lee' && $_POST['loginpass'] == '123456') {      header('location:http://bbs.csdn.net');} else {     } 

How can I modify this form to simulate login? why is it wrong?
Create a new 1.php
Header ('content-type: text/html; Charset = utf-8 '); $ user = 'Lil'; // login username $ pass = '2016 '; // login password $ post_fields = "loginname = {$ user} & loginpass = {$ pass}"; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, 'http: // localhost/2. php '); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_fields); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_exec ($ ch); curl_close ($ ch );


Reply to discussion (solution)

Echo curl_exec ($ ch );

In addition, your 2. php is redirected and no content is returned.
Change to echo file_get_contnets ('Location: http://bbs.csdn.net '); try

Header ('Location: http://bbs.csdn.net ');
Http header
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

Don't you follow the jump?
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true );

Header ('Location: http://bbs.csdn.net ');
Http header
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

Don't you follow the jump?
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true );
Thanks for your help. I changed it to this.
1. php

Header ('content-type: text/html; Charset = utf-8 '); $ user = 'Lil'; // login username $ pass = '2016 '; // login password $ post_fields = "loginname = {$ user} & loginpass = {$ pass}"; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, 'http: // localhost/2. php '); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_fields); curl_setopt ($ ch, expires, 1); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true); curl_exec ($ ch); curl_close ($ ch );

2. php
 header('Content-Type:text/html;Charset=utf-8');if ($_POST['loginname'] == 'lee' && $_POST['loginpass'] == '123456') {     header('location:http://bbs.csdn.net');} else {      }

The execution of 1.php is still blank and the redirection is not implemented.

#1. didn't you say that?
Echo curl_exec ($ ch );
How can you do this without outputting results?




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.