登陆页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head>
<!-- Main Stylesheet --> <link rel="stylesheet" href="{$Think.config.public_path}/css/style.css" type="text/css" media="screen" />
<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid --> <link rel="stylesheet" href="{$Think.config.public_path}/css/invalid.css" type="text/css" media="screen" />
<!-- Colour Schemes
Default colour scheme is green. Uncomment prefered stylesheet to use it.
不然如何能沟通呢?
你给的链接里不是有读取 cookie 的部分吗?
如果“无论怎么弄她都是固定的id”,那你读到的和发回去的不也是那个固定的id吗?
HttpHeader header = new HttpHeader();
header.accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
header.contentType = "application/x-www-form-urlencoded";
header.method = "POST";
header.userAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E";
header.maxTry = 200; CookieCollection mycookie = HTMLHelper.GetCookieCollection("http://localhost/gyjw/index.php/index/login_into",
"admin=admin&password=424", header); foreach (Cookie cookie in mycookie) //将cookie设置为浏览的cookie
{
InternetSetCookie( "http://" + cookie.Domain.ToString(), cookie.Name.ToString(), cookie.Value.ToString() + ";expires=Sun,22-Feb-2099 00:00:00 GMT"); }
//System.Diagnostics.Process.Start("http://localhost/gyjw/index.php/index/Login.html");
//System.Diagnostics.Process.Start("http://localhost/gyjw/index.php/index/login_into");
//System.Diagnostics.Process.Start("http://localhost/gyjw/index.php");
System.Diagnostics.Process.Start("http://localhost/gyjw/index.php/user/AddUser.html");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Threading;namespace WpfUI
{
public class HTMLHelper
{
/// <summary>
/// 获取CooKie
/// </summary>
/// <param name="loginUrl"></param>
/// <param name="postdata"></param>
/// <param name="header"></param>
/// <returns></returns>
public static CookieContainer GetCooKie(string loginUrl, string postdata, HttpHeader header)
{
HttpWebRequest request = null;
HttpWebResponse response = null;
try
{
CookieContainer cc = new CookieContainer();
request = (HttpWebRequest)WebRequest.Create(loginUrl);
request.Method = header.method;
request.ContentType = header.contentType;
byte[] postdatabyte = Encoding.UTF8.GetBytes(postdata);
request.ContentLength = postdatabyte.Length;
request.AllowAutoRedirect = false;
request.CookieContainer = cc;
request.KeepAlive = true; //提交请求
Stream stream;
stream = request.GetRequestStream();
stream.Write(postdatabyte, 0, postdatabyte.Length);
stream.Close(); //接收响应
response = (HttpWebResponse)request.GetResponse();
response.Cookies = request.CookieContainer.GetCookies(request.RequestUri); CookieCollection cook = response.Cookies;
//Cookie字符串格式
string strcrook = request.CookieContainer.GetCookieHeader(request.RequestUri); return cc;
}
catch (Exception ex)
{
throw ex;
}
} /// <summary>
/// 获取CookieCollection
/// </summary>
/// <param name="loginUrl"></param>
/// <param name="postdata"></param>
/// <param name="header"></param>
/// <returns></returns>
public static CookieCollection GetCookieCollection(string loginUrl, string postdata, HttpHeader header)
{
HttpWebRequest request = null;
HttpWebResponse response = null;
try
{
CookieContainer cc = new CookieContainer();
request = (HttpWebRequest)WebRequest.Create(loginUrl);
request.Method = header.method;
request.ContentType = header.contentType;
byte[] postdatabyte = Encoding.UTF8.GetBytes(postdata);
request.ContentLength = postdatabyte.Length;
request.AllowAutoRedirect = false;
request.CookieContainer = cc;
request.KeepAlive = true; //提交请求
Stream stream;
stream = request.GetRequestStream();
stream.Write(postdatabyte, 0, postdatabyte.Length);
stream.Close(); //接收响应
response = (HttpWebResponse)request.GetResponse();
response.Cookies = request.CookieContainer.GetCookies(request.RequestUri); CookieCollection cook = response.Cookies;
//Cookie字符串格式
string strcrook = request.CookieContainer.GetCookieHeader(request.RequestUri); return cook;
}
catch (Exception ex)
{ throw ex;
}
} /// <summary>
/// 获取html
/// </summary>
/// <param name="getUrl"></param>
/// <param name="cookieContainer"></param>
/// <param name="header"></param>
/// <returns></returns>
public static string GetHtml(string getUrl, CookieContainer cookieContainer,HttpHeader header)
{
Thread.Sleep(1000);
HttpWebRequest httpWebRequest = null;
HttpWebResponse httpWebResponse = null;
try
{
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(getUrl);
httpWebRequest.CookieContainer = cookieContainer;
httpWebRequest.ContentType = header.contentType;
httpWebRequest.ServicePoint.ConnectionLimit = header.maxTry;
httpWebRequest.Referer = getUrl;
httpWebRequest.Accept = header.accept;
httpWebRequest.UserAgent = header.userAgent;
httpWebRequest.Method = "GET";
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
string html = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();
httpWebRequest.Abort();
httpWebResponse.Close();
return html;
}
catch (Exception e)
{
if (httpWebRequest != null) httpWebRequest.Abort();
if (httpWebResponse != null) httpWebResponse.Close();
return string.Empty;
}
}
} public class HttpHeader
{
public string contentType { get; set; } public string accept { get; set; } public string userAgent { get; set; } public string method { get; set; } public int maxTry { get; set; }
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台登陆</title>
<!-- CSS -->
<!-- Reset Stylesheet -->
<link rel="stylesheet" href="{$Think.config.public_path}/css/reset.css" type="text/css" media="screen" />
<!-- Main Stylesheet -->
<link rel="stylesheet" href="{$Think.config.public_path}/css/style.css" type="text/css" media="screen" />
<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
<link rel="stylesheet" href="{$Think.config.public_path}/css/invalid.css" type="text/css" media="screen" />
<!-- Colour Schemes
Default colour scheme is green. Uncomment prefered stylesheet to use it.
<link rel="stylesheet" href="resources/css/blue.css" type="text/css" media="screen" />
<link rel="stylesheet" href="resources/css/red.css" type="text/css" media="screen" />
-->
<!-- Internet Explorer Fixes Stylesheet -->
<!--[if lte IE 7]>
<link rel="stylesheet" href="resources/css/ie.css" type="text/css" media="screen" />
<![endif]-->
<!-- Javascripts -->
<!-- jQuery -->
<script type="text/javascript" src="{$Think.config.public_path}/scripts/jquery-1.3.2.min.js"></script>
<!-- jQuery Configuration -->
<script type="text/javascript" src="{$Think.config.public_path}/scripts/simpla.jquery.configuration.js"></script>
<!-- Facebox jQuery Plugin -->
<script type="text/javascript" src="{$Think.config.public_path}/scripts/facebox.js"></script>
<!-- jQuery WYSIWYG Plugin -->
<script type="text/javascript" src="{$Think.config.public_path}/scripts/jquery.wysiwyg.js"></script>
<!-- Internet Explorer .png-fix -->
<!--[if IE 6]>
<script type="text/javascript" src="resources/scripts/DD_belatedPNG_0.0.7a.js"></script>
<script type="text/javascript">
DD_belatedPNG.fix('.png_bg, img, li');
</script>
<![endif]-->
</head>
<body id="login">
<div id="login-wrapper" class="png_bg">
<div id="login-top">
<h1>系统</h1>
<!-- Logo (221px width) -->
<img id="logo" src="{$Think.config.public_path}/images/logo.png" />
</div> <!-- End #logn-top -->
<div id="login-content">
<form action="__URL__/login_into" method="post">
<!-- <div class="notification information png_bg">
<div>
Just click "Sign In". No password needed.
</div>
</div>-->
<p>
<label>用户名</label>
<input name="admin" class="text-input" type="text" />
</p>
<div class="clear"></div>
<p>
<label>密 码</label>
<input name="password" class="text-input" type="password" />
</p> <div class="clear"></div>
<p>
<input class="button" type="submit" value="登录" />
</p>
</form>
</div> <!-- End #login-content -->
</div> <!-- End #login-wrapper -->
</body>
</html>
tp 的表单有可能使用了 token,也要处理的模拟登录的流程是:
1、访问登陆页,获取表单元素名和值(已知的话可跳过)
2、获取 cookie、获取可能存在的 token
3、获取可能存在的验证码图片并解析。如果有验证码,还需重新获取 cookie
4、发送应提交的数据集合和 cookie 到表单目标页
password:424
__hash__:9dcee4d5bcfb44270f8cbfaebbc2d786_a57a03650a2256a207ed4f6ccaad6bf0
没有验证码,这个__hash__是您指的token吗?
你怎么总是取检查 session 呢?方向错了
哪个方向错了啊!大神多指点指点,不懂呢
PHPSESSID:.................
你打印出的数据中没有这样的内容
下面我把session的内容发出来,您给看看,该怎么弄。
先发生成的固定session,sess_60k402oc795mpvihq9jodpnml7
GuestName|s:5:"admin";UserId|N;__hash__|a:2:{s:32:"29b296010dbae92683f9cfada6743386";s:32:"f6f026587c241f4f2f6f94ed4e957ccb";s:32:"d150a69b13ade312006133d91f4fc9b1";s:32:"ef751c9ebc0066c0a98731b2b819ac98";}
再发随机生成的session,sess_ln3gn3acd5a6arme32h3viq3e5
GuestName|s:5:"admin";UserId|N;
如果不打开客户端直接网站登录,那么只会生成固定的那个session;如果打开客户端登录,就会先生成一个随机的,当通过客户端打开浏览器登录时,又会生成一个固定的,此时固定的没有GuestName信息。
其中GuestName是用户名的信息,网站的一切操作权限都是关联的这个GuestName,UserId始终是N,不知道是什么意思,__hash__我感觉是操作生成的记录信息,因为每一个页面跳转操作都会刷新__hash__内容。
我的问题出在哪里呢?
你打开php.ini 看一下session.gc_probability和session.gc_divisor的值分别是多少,这两个值影响session的刷新概率
现在你估计只要把里面的session.gc_probability设为0就能保证session不刷新
生成的临时文件为 sess_60k402oc795mpvihq9jodpnml7
至于里面是什么内容,则是有你的程序决定的,与旁人无关此时 cookie 中会有 PHPSESSID:60k402oc795mpvihq9jodpnml7 项
如果你的客户端程序没有读到他,就表示你的客户端程序有问题
鉴于你的客户端是 C# 的,你应该到 .net 版面去求解,显然那边 C# 的水平高于这里
你的客户端只是模拟了浏览器的行为,自然也不需要懂 phpthink
嗯,还懂 js