php后台登陆页⾯代码
login.php
<?php
session_start();
>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>公司事务 - 登录</title>
<link href="skin/css/login.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="login">
<div class="system">
<h1>分销系统</h1>
</div>
<div class="form">
<h2>登录系统</h2>
<div class="error">
</div>
<form name="regform" method="post" action="handle_login.php?act=login">
<label for="">⽤户名:</label>
<p><span class="input"><input type="text" name="username" /></span></p>
<label for="">密 ;码:</label>
<p><span class="input"><input type="password" name="passwd" /></span></p>
<label for="">验证码:</label>
<p><span class="inputYzm"><input type="text" name="code" /></span><a href="####" class="yzm"><img src="code.php" /></p>
<p class="buttonWrapper">
<input class="buttonLogin" type="submit" name="submit" value="登录" />
</p>
</form>
</div>
</div>
</body>
</html>
code.php
<?php
Header("Content-type: p_w_picpath/gif");
/*
* 初始化
*/
$border = 1; //是否要边框 1要:0不要
$how = 4; //验证码位数
$w = $how*15; //图⽚宽度
$h = 20; //图⽚⾼度
$fontsize = 5; //字体⼤⼩
$alpha = "abcdefghijkmnopqrstuvwxyz"; //验证码内容1:字母
$number = "023456789"; //验证码内容2:数字
$randcode = ""; //验证码字符串初始化
srand((double)microtime()*1000000); //初始化随机数种⼦
$im = ImageCreate($w, $h); //创建验证图⽚
/*
* 绘制基本框架
*/
$bgcolor = ImageColorAllocate($im, 255, 255, 255); //设置背景颜⾊
ImageFill($im, 0, 0, $bgcolor); //填充背景⾊
if($border)
{
$black = ImageColorAllocate($im, 0, 0, 0); //设置边框颜⾊
ImageRectangle($im, 0, 0, $w-1, $h-1, $black);//绘制边框
}
/*
* 逐位产⽣随机字符
*/
for($i=0; $i<$how; $i++)
{
$alpha_or_number = mt_rand(0, 1); //字母还是数字
$str = $alpha_or_number ? $alpha : $number;
$which = mt_rand(0, strlen($str)-1); //取哪个字符
$code = substr($str, $which, 1); //取字符
$j = !$i ? 4 : $j+15; //绘字符位置
$color3 = ImageColorAllocate($im, mt_rand(0,100), mt_rand(0,100), mt_rand(0,100)); //字符随即颜⾊
ImageChar($im, $fontsize, $j, 3, $code, $color3); //绘字符
$randcode .= $code; //逐位加⼊验证码字符串
}
/*
* 添加⼲扰
*/
/
*
for($i=0; $i<5; $i++)//绘背景⼲扰线
{
$color1 = ImageColorAllocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); //⼲扰线颜⾊
ImageArc($im, mt_rand(-5,$w), mt_rand(-5,$h), mt_rand(20,300), mt_rand(20,200), 55, 44, $color1); //⼲扰线}
for($i=0; $i<$how*40; $i++)//绘背景⼲扰点
{
$color2 = ImageColorAllocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); //⼲扰点颜⾊
ImageSetPixel($im, mt_rand(0,$w), mt_rand(0,$h), $color2); //⼲扰点
}
*/
//把验证码字符串写⼊session
session_start();
$_SESSION['code'] = $randcode;
/*绘图结束*/
ob_clean();
Imagegif($im);
ImageDestroy($im);
/*绘图结束*/
>
conn.php
<?php
mysql_connect("127.0.0.1:3306","root","123456") or die("连接数据库失败!");
mysql_selectdb("bigagent")or die("db连接失败");
//mysql_set_charset("gbk");
mysql_query("set names 'utf8'");
>
handle_login.php
<?php
include("conn.php");
header("Content-type:text/html;charset=utf-8");
session_start () ;
echo var_dump($_SESSION['code']);
$action=$_GET['act'];
switch ($action){
case 'login';
login();
break;
default:
break;
}
function login(){
if(isset($_POST['submit']) and $_POST['username']!=null and $_POST['passwd']!=null){
$user=$_POST['username'];
$pass=md5($_POST['passwd']);
echo $sql="select * from admins where username = '$user'";
$result=mysql_query($sql);
$arry_row=mysql_fetch_array($result);
echo var_dump($arry_row);
if(!$arry_row){
echo "<script>alert('⽤户名不存在!');location.href='login.php'</script>";
exit();
}
if($pass == $arry_row['passwd']){
if ($_POST['code'] == $_SESSION['code']){
$_SESSION['id']=$arry_row['id'];
$_SESSION['user_share']=md5($arry_row['id'].$arry_row['passwd']);
/*
session下载if($row_arry['active']< 1){
echo "<script>alert('此⽤户未激活,请到邮箱中激活账户!');location.href='login.php'</script>"; }
*/
header("location:index.php");
// echo "<script>location.href='index.php'</script>";
}else{
echo "<script>alert('验证码错误!');location.href='login.php'</script>";
}
}else{
echo "<script>alert('密码错误!');location.href='login.php'</script>"; }
}
else
{
echo "<script>alert('⽤户名密码不为空!');location.href='login.php'</script>"; }
}
/*
$str_number = trim($_POST['number']);
if(strtolower($_SESSION['rand'])==strtolower($str_number )){
echo "验证码正确";
}else{
echo "验证码不正确";
}
*/
>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论