PHP uses curl to simulate the way to log in to the campus Renren

Source: Internet
Author: User
This article mainly introduces PHP using curl to achieve the simulation of the method of the campus Renren, interested in the friend's reference, I hope to help you.

PHP uses curl to simulate a simple example of logging in to everyone (campus) network

$login _url = ' http://passport.renren.com/PLogin.do '; $post _fields[' email '] = ' XXXX '; $post _fields[' password '] = ' XXXX '; $post _fields[' origurl '] = ' http%3a%2f%2fhome.renren.com%2fhome.do '; $post _fields[' domain '] = ' renren.com ';  The cookie file is stored under the Temp folder in the root directory of the Web site $cookie _file = Tempnam ('./temp ', ' Cookie '); $ch = Curl_init ($login _url); curl_setopt ($ch, Curlopt_useragent, ' mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9.1.5) gecko/20091102 firefox/3.5.5 '); curl_setopt ($ch, Curlopt_header, 0); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_maxredirs, 1); curl_setopt ($ch, curlopt_followlocation, 1); curl_setopt ($ch, Curlopt_autoreferer, 1); curl_setopt ($ch, Curlopt_post, 1); curl_setopt ($ch, Curlopt_postfields, $post _fields); curl_setopt ($ch, Curlopt_cookiejar, $cookie _file); Curl_exec ($ch);  Curl_close ($ch); Bring a cookie file, visit Renren homepage $send _url= ' http://home.renren.com/Home.do '; $ch = Curl_init ($send _url); curl_setopt ($ch, Curlopt_header, 0); curl_setopt ($ch, Curlopt_returnTRANSFER, 1); curl_setopt ($ch, Curlopt_cookiefile, $cookie _file); $contents = curl_exec ($ch);  Curl_close ($ch);  Clean cookie file unlink ($cookie _file); Output Renren Home page content Print_r ($contents);

Summary: The above is the entire content of this article, I hope to be able to help you learn.

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.