php入门教程之用户认证
2008-10-30 17:27
393 查看
原文:http://tutorial.jcwcn.com/Web-Design/PHP/User-Authentication/2007-08-24/3015.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户认证--注意没有加密</title>
</head>
<body>
<?php
session_start();
mysql_connect("localhost","root","123456");
mysql_select_db("test");
if(isset($_POST['logout'])) {
$_SESSION = array();
session_destroy();
echo "您已经成功退出! 单击 <a href='user.php'>这里</a> 继续!";
}else{
if(isset($_SESSION['logged'])) { //如果用户已经登录
echo "欢迎 ".$_SESSION['username']; //显示欢迎信息
?>
<form method='POST' action='user.php'>
<input type='submit' value='注销' name='logout'>
</form>
<?php
}else{ //否则没有登录
if(isset($_POST['submit'])&&isset($_POST['usr'])&&isset($_POST['pwd'])) {
if(mysql_num_rows(mysql_query("SELECT id FROM accounts WHERE username = '".$_POST['usr']."' && password = '".$_POST['pwd']."' ")) > 0 ) {
$_SESSION['logged'] = true;
$_SESSION['username'] = $_POST['usr'];
$_SESSION['password'] = $_POST['pwd'];
echo "<font color='green'>你已经成功登录!</font>";
header("refresh:3;url='user.php'");//3秒后跳转
}else{
echo "<font color='red'>登录失败.请重试!</font>";
header("refresh:1;url='user.php'");
}
}else{ //如果用户没有按下submit提交按钮,则显示此表单
?>
<form method='POST' action=''>
<b>用户名:</b> <input type='text' name='usr'><br>
<b>密码:</b> <input type='password' name='pwd'><br>
<input type='submit' value='login' name='submit'>
</form>
<?php
}
}//用户未登录
}
?>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户认证--注意没有加密</title>
</head>
<body>
<?php
session_start();
mysql_connect("localhost","root","123456");
mysql_select_db("test");
if(isset($_POST['logout'])) {
$_SESSION = array();
session_destroy();
echo "您已经成功退出! 单击 <a href='user.php'>这里</a> 继续!";
}else{
if(isset($_SESSION['logged'])) { //如果用户已经登录
echo "欢迎 ".$_SESSION['username']; //显示欢迎信息
?>
<form method='POST' action='user.php'>
<input type='submit' value='注销' name='logout'>
</form>
<?php
}else{ //否则没有登录
if(isset($_POST['submit'])&&isset($_POST['usr'])&&isset($_POST['pwd'])) {
if(mysql_num_rows(mysql_query("SELECT id FROM accounts WHERE username = '".$_POST['usr']."' && password = '".$_POST['pwd']."' ")) > 0 ) {
$_SESSION['logged'] = true;
$_SESSION['username'] = $_POST['usr'];
$_SESSION['password'] = $_POST['pwd'];
echo "<font color='green'>你已经成功登录!</font>";
header("refresh:3;url='user.php'");//3秒后跳转
}else{
echo "<font color='red'>登录失败.请重试!</font>";
header("refresh:1;url='user.php'");
}
}else{ //如果用户没有按下submit提交按钮,则显示此表单
?>
<form method='POST' action=''>
<b>用户名:</b> <input type='text' name='usr'><br>
<b>密码:</b> <input type='password' name='pwd'><br>
<input type='submit' value='login' name='submit'>
</form>
<?php
}
}//用户未登录
}
?>
</body>
</html>
相关文章推荐
- php版微信公众平台入门教程之开发者认证的方法
- PHP入门教程-hello world
- 【PHP面向对象(OOP)编程入门教程】如何去使用对象中的成员
- Shiro入门2:权限管理入门,用户认证、授权
- 基于PHP的cURL快速入门教程 (小偷采集程序)
- PHP依赖管理工具Composer入门教程
- PHP版 RabbitMQ官方中文入门教程
- flask入门的教程-(用户信息页和头像) Profile Page And Avatars
- PHP正则表达式入门教程[转]
- C#入门教程(三)–接收用户输入、转义字符、类型转换-打造C#入门教程
- PHP快速入门教程:WHILE循环示例
- 【PHP面向对象(OOP)编程入门教程】6.如何去使用对象中的成员
- 【PHP面向对象(OOP)编程入门教程】14.final关键字的应用
- 【PHP面向对象(OOP)编程入门教程】21.多态的应用
- 【转】PHP字符串操作入门教程
- php中的curl使用入门教程和常见用法实例
- 【Java mail 入门教程】第五讲 邮件认证
- 79. 基于 PHP 的用户认证
- php中的curl使用入门教程和常见用法实例-上
- Ajax+PHP简单入门教程