您的位置:

php模拟用户登录,php 登录

本文目录一览:

怎样用php中的curl模拟登陆

在我的博客《PHP cURL模拟登录与采集分析过程详解》做了详细的介绍,步骤有:

1. 访问目标网站

2. 打开Firebug(快捷键:F12)

3. 清除【Cookie】

4. 重新访问目标网站

5. 设置【网络】为[保持]状态

6. 填写表单,提交登录请求

7. 利用【网络】,分析提交信息

8. 复制请求的cURL命令

9. 分析命令传输的参数与Cookie和前面页面响应内容的关联性

10. 如果遇到Cookie和响应内容都无法查找到的参数,Ctrl+S保存当前页面为全部,利用文本搜索该参数的位置

11. 利用cURL命令组装模拟登录程序

详情请参考博客内容:

PHP模拟用户登录模块

html(login.html)

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""

html xmlns=""

head

meta http-equiv="Content-Type" content="text/html; charset=gb2312" /

title用户登录页面/title

script language="javascript"

function check(){

var user = document.getElementById("user");

var passwd = document.getElementById("passwd");

if(user.value.length == 0){

alert("用户名不能为空!");

return false;

}

if(passwd.value.length  6){

alert("密码至少6位!");

return false;

}

}

/script

/head

body

div style=" width:300px; height:200px; margin:auto auto;"

form name="login" method="post" action="check_login.php"

table width="300" height="200" cellpadding="0" cellspacing="0" border="1px"

tr

td height="70"用户名:/td

tdinput id="user" name="username" type="text" //td

/tr

tr

td height="78"密码/td

tdinput id="passwd" name="password" type="password" //td

/tr

tr

td colspan="2"centerinput type="submit" value="登录" onclick="return check();" /input type="reset" value="重置" //center/td

/tr

/table

/form

/div

/body

/html

php(check_login.php)

?php

/*

* 验证登录页

* 2015-6-6

* 预设用户名admin,密码1234567,

*  如果相同则显示登录成功!,错误则显示用户或密码错误;

*/

$username = $_POST['username'];

$password = $_POST['password'];

if($username == 'admin'  $password =='1234567'){

echo "登录成功!";

}else{

echo "用户或密码错误";

}

?

如何通过php程序模拟用户登录

模拟用户可以用php的curl的post,例如

$url = "";

$post_data = array ("username" = "uzuzuz","password" = "12345");

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// post数据

curl_setopt($ch, CURLOPT_POST, 1);

// post的变量

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

$output = curl_exec($ch);

curl_close($ch);

//打印获得的数据

print_r($output);

具体参考: