Analysis of php simulated login implementation methods

Source: Internet
Author: User
This article mainly introduces the implementation of php simulated login. The example analyzes the implementation methods of snoopy and curl, which has some reference value, if you need it, you can refer to the example in this article to analyze the implementation of php simulated login. Share it with you for your reference. The specific analysis is as follows:

Php simulated login implementation method. here are two methods to simulate login to Renren. The specific instance code is as follows:

1) use snoopy to simulate logon:

The code is as follows:

<? Php
Set_time_limit (0 );
Require "Snoopy. class. php ";
$ Snoopy = new Snoopy ();
$ Snoopy-> referer = 'http: // www.bitsCN.com /';
$ Snoopy-> agent = "Mozilla/5.0 (Windows NT 6.1; rv: 22.0) Gecko/20100101 Firefox/22.0 ";
$ Submit_vars ['email '] = 'logon account ';
$ Submit_vars ['password'] = 'logon password ';
$ Url = 'http: // www.bitscn.com/test/login.php'#//urladdress provided by the login data
$ Snoopy-> submit ($ url, $ submit_vars );
$ Snoopy-> fetch ("http://www.bitsCN.com/"); // page data to be retrieved
Echo $ snoopy-> results; // m.bitsCN.com


2) use curl to simulate login:

The code is as follows:

<? Php
Set_time_limit (0 );
$ Cookie_file = tempnam ('./tmp', 'cooke'); // The tmp directory must be created first.
$ Ch = curl_init ();
$ Login_url = 'http: // www.bitscn.com/plogin.do ';
$ CurlPost = "email = logon account & password = logon password ";
Curl_setopt ($ ch, CURLOPT_URL, $ login_url );
// When enabled, the header file information is output as a data stream.
Curl_setopt ($ ch, CURLOPT_HEADER, 0); // you can specify whether to output the page content.
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_POST, 1); // you can specify the request sending method, such as post or get, CURLOPT_POST, or CURLOPT_GET.
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ curlPost );
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ cookie_file); // Save the cookie
Curl_exec ($ ch );
Curl_close ($ ch );
$ Ch = curl_init ();
$ Login_url2 = "http://www.bitsCN.com /";
Curl_setopt ($ ch, CURLOPT_URL, $ login_url2 );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 0 );
Curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookie_file); // read cookie
Curl_exec ($ ch );
Curl_close ($ ch );

I hope this article will help you with php programming.

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.