简易登录

登录代码:<?php ob_start(); include('header.html'); print '<body>'; ?><?php if($_SERVER['REQUEST_METHOD']=='POST') { $_mysqli= new mysqli(); $_mysqli->connect('localhost','root','galgaddott'); $dbc=$_mysqli->select_db('shujuku1'); if($dbc) { $query="SELECT * FROM denglu1"; $result=mysqli_query($_mysqli,$query); if(mysqli_connect_errno($result)) { print 'can not receive the table!';} else { while($row=mysqli_fetch_array($result))//匹配 { if (($_POST['name']==$row['zhanghao'])&& ($_POST['password']==$row['mima'])) { setcookie('zhanghao',$_POST['name'],time()+3600,"/"); setcookie('mima',$_POST['password'],time()+3600,"/"); print '登陆成功,页面将于3秒内跳转!'; $_mysqli->close(); header('refresh:3; url=welcome.php');//欢迎界面还没写 exit;} } print '请输入正确的账号密码!'; print '信息错误!页面将于3秒内刷新!'; header('refresh:3; url=login1.php'); $_mysqli->close(); exit;}?>
注册代码:

ob_start();
include('header.html');
print '<body>';
?>
<form action="new.php" method="post">
<p>账号:<input type="text" name="name1" /></p>
<p>密码:<input type="password" name="password1" /></p>
<p><input type="submit" value="确认注册" /></p>
</form>
<?php
error_reporting(0);
if($_SERVER['REQUEST_METHOD']=='POST')
{$_mysqli= new mysqli();
$_mysqli->connect('localhost','root','galgaddott');
$dbc=$_mysqli->select_db('shujuku1');
if($dbc)
{$query="INSERT INTO denglu1(zhanghao,mima) VALUES( {$_POST[name1]},{$_POST[password1]})";
$a=mysqli_query($_mysqli,$query);
if(mysqli_connect_errno($a))
{print '注册失败!于3秒内返回登录界面!';
header('refresh:3; url=login1.php');
exit;
}
else{ setcookie('zhanghao',$_POST['name'],time()+3600,"/");
    setcookie('mima',$_POST['password'],time()+3600,"/");
print '登陆成功,页面将于3秒内跳转!';
header('refresh:60; url=welcome.php');
exit;
}
}
else {
print '注册失败!于3秒内返回登录界面!';
header('refresh:3; url=login1.php');
exit;
}
}
?></form>
</body>
</html>

待做:加上cookie,给账号密码做相应检测等.

展开阅读全文
©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值