Maison php教程 php手册 php curl模拟登陆人人网发表状态

php curl模拟登陆人人网发表状态

Jun 02, 2016 am 09:13 AM

在php中要实现用户登录我们一般都会到curl模拟登陆功能,下面我就基于php的curl来实现登录人人网,完整的例子希望对各位有帮助,代码如下:

<?php 
	$cookie_file = dirname(__FILE__)."/renren.cookie"; 
	 
	$login_url = &#39;http://passport.renren.com/PLogin.do&#39;; 
	 
	$post_fields[&#39;email&#39;] = &#39;&#39;;//人人的帐号 
	$post_fields[&#39;password&#39;] = &#39;&#39;;//人人密码 
	$post_fields[&#39;origURL&#39;] = &#39;http%3A%2F%2Fhome.renren.com%2FHome.do&#39;; 
	$post_fields[&#39;domain&#39;] = &#39;renren.com&#39;; 
	 
	 
	$ch = curl_init($login_url); 
	curl_setopt($ch, CURLOPT_USERAGENT, &#39;Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5&#39;); 
	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); 
	$content = curl_exec($ch); 
	curl_close($ch); 
	//匹配用户的ID 
	$send_url=&#39;http://www.renren.com/home&#39;; 
	$ch = curl_init($send_url); 
	curl_setopt($ch, CURLOPT_HEADER, 0); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
	curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); 
	curl_exec($ch); 
	$info = curl_getinfo($ch); 
	curl_close($ch); 
	//获取用户id 
	$tmp = explode(&#39;/&#39;,$info[&#39;redirect_url&#39;]); 
	$uid = array_pop($tmp); 
	unset($tmp); 
	 
	//$uid = "305115027"; 
	//获取token和rtk 
	 
	$send_url=&#39;http://www.renren.com/&#39;.$uid; 
	$ch = curl_init($send_url); 
	curl_setopt($ch, CURLOPT_HEADER, 0); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
	curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); 
	$tmp = curl_exec($ch); 
	curl_close($ch); 
	preg_match_all("/get_check:&#39;(.*?)&#39;,get_check_x:&#39;(.*?)&#39;,/is",$tmp,$arr); 
	$token = $arr[1][0];//1121558104 
	$rtk = $arr[2][0];//e9a9cb2 
	 
	//发布信息 
	$poststr[&#39;content&#39;] = "这就是一个测试而已!!!"; 
	$poststr[&#39;withInfo&#39;] = &#39;{"wpath":[]}&#39;; 
	$poststr[&#39;hostid:&#39;] = $uid; 
	$poststr[&#39;privacyParams&#39;] = &#39;{"sourceControl": 99}&#39;; 
	$poststr[&#39;requestToken&#39;] = $token; 
	$poststr[&#39;_rtk&#39;] = $rtk; 
	$poststr[&#39;channel&#39;] = "renren"; 
	 
	$head = array( 
	   &#39;Referer:http://shell.renren.com/ajaxproxy.htm&#39;, 
	   &#39;X-Requested-With:XMLHttpRequest&#39;, 
	  ); 
	$ch = curl_init("http://shell.renren.com/{$uid}/status"); 
	curl_setopt($ch, CURLOPT_USERAGENT, &#39;Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5&#39;); 
	curl_setopt($ch,CURLOPT_HTTPHEADER,$head); 
	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, $poststr); 
	curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); 
	$content = curl_exec($ch);//开源代码phprm.com 
	curl_close($ch); 
	$data = json_decode($content,true); 
	if($data["code"] == "0"){ 
	 echo "发布成功!"; 
	}else{ 
	 echo "shit !!!"; 
	}
Copier après la connexion

本文地址:

转载随意,但请附上文章地址:-)

Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Outils d'IA chauds

Undresser.AI Undress

Undresser.AI Undress

Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover

AI Clothes Remover

Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool

Undress AI Tool

Images de déshabillage gratuites

Clothoff.io

Clothoff.io

Dissolvant de vêtements AI

AI Hentai Generator

AI Hentai Generator

Générez AI Hentai gratuitement.

Article chaud

R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
2 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Meilleurs paramètres graphiques
2 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Comment réparer l'audio si vous n'entendez personne
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌

Outils chauds

Bloc-notes++7.3.1

Bloc-notes++7.3.1

Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver CS6

Dreamweaver CS6

Outils de développement Web visuel

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)