Curl Simulation Login Implementation Tutorial

Source: Internet
Author: User
Tags auth curl

Analog Landing 126 mailbox, Renren and other according to the need to modify their own Ah, the code is as follows

Analog login authentication Code of the website, first get the verification code picture of the cookie

Define (' Script_root ', DirName (__file__). /');

$cookieFile = script_root. ' Cookie.tmp ';

/* Analog Browser * *

$user _agent = "mozilla/4.0" (compatible; MSIE 6.0; Windows NT 5.2. NET CLR 1.1.4322) ";

Here if you know the cookie can be sent directly to the target browser

$cookie = "LANG=ZH-CN; Jsessionid=6af7da3f6a5fc3eca39a7485c3fdbbae ";

$header = Array (

"Host:login.biuman.com",

"Referer:http://www.biuman.com",

);

The URL of the verification code picture

function GetCookie ($url) {

Global $cookieFile;

$curl = Curl_init (); Start a Curl session

curl_setopt ($curl, Curlopt_url, $url); The address to access

curl_setopt ($curl, Curlopt_ssl_verifypeer, 0); Inspection of the source of certification certificate

curl_setopt ($curl, Curlopt_ssl_verifyhost, 1); Check to see if the SSL encryption algorithm exists from the certificate

curl_setopt ($curl, Curlopt_httpget, 1); Send a regular GET request

curl_setopt ($curl, Curlopt_cookiejar, $cookieFile); Save the returned cookie information in a file

$res = curl_exec ($curl);

Curl_close ($curl);

}

function Login ($url) {

Global $cookieFile, $header, $agent;

$data = Array (

' Name ' => ' Biuman '

);

$curl = Curl_init (); Start a Curl session

curl_setopt ($curl, Curlopt_url, $url); The address to access

curl_setopt ($curl, Curlopt_ssl_verifypeer, 0); Inspection of the source of certification certificate

curl_setopt ($curl, Curlopt_ssl_verifyhost, 1); Check to see if the SSL encryption algorithm exists from the certificate

curl_setopt ($curl, curlopt_useragent, $agent); Impersonate a browser used by a user

curl_setopt ($curl, Curlopt_httpheader, $header); Where to set header information

@curl_setopt ($curl, curlopt_followlocation, 1); Use automatic jump

curl_setopt ($curl, Curlopt_httpget, 1); Send a regular GET request

curl_setopt ($curl, Curlopt_post, 1); Send a regular POST request

curl_setopt ($curl, Curlopt_postfields, $data); Post-Submitted packets

curl_setopt ($curl, Curlopt_cookie, $cookie); Send cookie content directly

curl_setopt ($curl, Curlopt_cookiefile, $cookieFile); Send Cookie File

curl_setopt ($curl, Curlopt_timeout, 120); Set timeout limit to prevent dead loops

curl_setopt ($curl, Curlopt_header, 0); Does not display the returned header area contents

curl_setopt ($curl, Curlopt_returntransfer, 1); Gets the information returned in the form of a file stream

$res = curl_exec ($curl); Perform an action

if (Curl_errno ($curl)) {

Return ' failed: Errno '. Curl_error ($curl);

}

Curl_close ($curl); Close Curl Session

return $res;

}

1.

$auth _url = "Http://www.biuman.com/auth";

GetCookie ($auth _url); Get the authentication Code cookie

2.

$url = ' http://www.biuman.com/home '; URLs submitted after landing

$res = login ($url);

Print_r ($res);

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.