$dbhost = "localhost";
$dbname = "passport";
$dbuser = "root";
$dbpassword ="sa";
$link =@mysql_pconnect("$dbhost","$dbuser","$dbpassword");
if (!$link)
{
echo 'Could not connect to mysql';
exit;
}
else
mysql_select_db($dbname,$link);//数据库连接
$sql="select * from tablename where username='www' and passwrod='123'";
$query=mysql_query($sql,$link);
$num=mysql_num_rows($query);
$y2k=time()+60*60*24*30;//设置cook 存在时间
session_start();//开启session
if($num==1)
{
echo "欢迎回来";
setcookie("cook_name", "www",$y2k);
setcookie("cook_pwd", "123",$y2k);
$_SESSION["username"]="www";
}
else
{
echo "用户名或者密码不正确";
}
string name = TextBox1.Text;
string pass = TextBox2.Text;
if (name == "admin" && pass == "123")
{
Session["abc"] = "admin";
Session.Timeout = 1;
Response.Redirect("main.aspx");
}//main.aspx 页面 if (Session["abc"] == null)
{
Response.Redirect("Default.aspx");
}
else
{
Label1.Text = "欢迎你,"+Session["abc"].ToString();
}