PHP采用curl模仿用户登陆新浪微博发微博的方法,curl用户登陆
PHP采用curl模仿用户登陆新浪微博发微博的方法,curl用户登陆
本文实例讲述了PHP采用curl模仿用户登陆新浪微博发微博的方法。分享给大家供大家参考。具体实现方法如下:
现在用php做模仿用户登录我们都会使用到PHP curl函数了,因为只有它才可以实现像用户一样的去访问别人网站了,下面就给大家介绍一下curl登陆新浪微博发微博应用例子。
前天接到一个需求需要模拟登陆微博然后进行发微博,以前干过很多的模拟登录阿里妈妈,微信,还有些其他的内部系统,至今没有出现不能登录的,哈哈,所以也就没有当一回事情,可是当分析新浪的登陆过程的时候才感觉到压力
遇到sha1(sha1(sha1(pwd)).once.servertime) ,肯定都用不了,主要使这个加密算法搞不定所以密码都搞不定别谈登录的,接着就在网上各种找代码,一个小时毫无所获。
是不是我用微博的帐号密码也能登录到新浪邮箱或者其他新浪产品去,感觉希望很大,果然微博的帐号可以直接登录所有的新浪产品,再次访问微博我已经在登录状态了,证明这个有神马用呢?
其实很有用的,一个大公司在一个项目投入的技术和这个项目盈利和前景有很大关系,微博他可以花很大的心思去做,但是其他就不一定,万一找到那个地方的密码没有加密那岂不是很好说了。(PS:对网络安全比较感兴趣,这个方式对黑客来说叫做旁注,旁注就是,当黑客在攻击一个网站的时候,这个网站安全做的非常好,没有什么已知漏洞,攻破难度较大,所以黑客会找找该网站下服务器下其他网站,然后找一个比较容易攻破的,通过这个网站挂马,shell,提权,然后目标网站也就沦陷,以为在同一个服务器,所以….目标就是拿到目标站,无论哪种方法只要拿下就行,很淫荡的想法有没有)
https://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.15)&_=1403138799543简单抓抓包发现密码并没有加密,我们不是能模拟登录了吗? 嗯,其实这里高兴的有点早了
先登录新浪的吧,代码分分钟就搞定了。返回的是一个json数组
复制代码 代码如下:
$password = $p;
$username = base64_encode($u);
$loginUrl = 'https://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.15)&_=1403138799543';
$loginData['entry'] = 'sso';
$loginData['gateway'] = '1';
$loginData['from'] = 'null';
$loginData['savestate'] = '30';
$loginData['useticket'] = '0';
$loginData['pagerefer'] = '';
$loginData['vsnf'] = '1';
$loginData['su'] = base64_encode($u);
$loginData['service'] = 'sso';
$loginData['sp'] = $password;
$loginData['sr'] = '1920*1080';
$loginData['encoding'] = 'UTF-8';
$loginData['cdult'] = '3';
$loginData['domain'] = 'sina.com.cn';
$loginData['prelt'] = '0';
$loginData['returntype'] = 'TEXT';
//var_dump($loginData);exit;
$login = json_decode(loginPost($loginUrl,$loginData),true);
var_dump($login);exit;function loginPost($url,$data){
global $cookie_file ;
//echo $cookie_file ;exit;
$tmp = '';
if(is_array($data)){
foreach($data as $key =>$value){
$tmp .= $key."=".$value."&";
}
$post = trim($tmp,"&");
}else{
$post = $data;
}
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);
$return = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return $return;
}
返回的是一个json数据转成数组即可
复制代码 代码如下:
array (size=4)
'retcode' => string '0' (length=1)
'uid' => string '1920109964' (length=10)
'nick' => string '毕姥爷讲故事' (length=18)
'crossDomainUrlList' =>
array (size=2)
0 => string 'https://passport.weibo.com/wbsso/login?ticket=ST-MTkyMDEwOTk2NA%3D%3D-1403228192-gz-AB37DC0C18BA3BFCD90AEFAC6115149D&ssosavestate=1434764192' (length=140)
1 => string 'https://crosdom.weicaifu.com/sso/crosdom?action=login&savestate=1434764192' (length=74)
这个时候说明我们登录成功了,但是其实我们的微博首页的地址并不是weibo,com,而是 http://weibo.com/bipeng0405/home?wvr=5 这样地址,我们怎么获取这个地址了,很简单,直接抓取weibo。com然后他会自动给你跳转回去的,你只需要把跳转的地址记录下来即可
复制代码 代码如下:
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"http://weibo.com");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);
$return = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
这里还有一个问题,这个时候你可能发现没有跳转到自己微博的首页,这是什么原因呢,可以看看登陆时候有两个连接地址,其中有一个weibo域下的一个地址,猜测应该是进行了cookie的设置所以先获取一边他吧。
复制代码 代码如下:
get($login['crossDomainUrlList'][0]);
这个代码要在刚才weibo.com获取之前,否则会出现问题的。
希望本文所述对大家的PHP程序设计有所帮助。
php 通过curl怎模拟登陆新浪微博
呵呵,我在寻找curl模拟登陆微信公众平台的资料
PHP CURL POST模拟用户登录了希望可以给出具体的代码,并简要解释下代码
你可以看下是否有其它的http header没有模拟,比如Referer和User-Agent是否都能模拟浏览器的值,一个完整的请求是类似于这样的:
GET /home/pack/data/content?id=31,2399,13,30&asyn=1&t=0.03439752989200834&_req_seqid=0xa982225f0637c78a HTTP/1.1
Accept: */*
Accept-Language: zh-cn
Referer: www.baidu.com/
x-requested-with: XMLHttpRequest
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; BTRS123401; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; MS-RTC LM 8)
Host: www.baidu.com
Connection: Keep-Alive
Cookie: XCXXXXX

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
