Login - thiet ke web

Màu nền
Font chữ
Font size
Chiều cao dòng

<!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>Untitled Document</title>

</head>

<body>

<?php

// Đừng bao giờ quên dòng này để khởi động session

session_start();

// UserId và password đặt trước

$userId='demo';

$password='demo';

$errorMessage = '';

if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {

if (($userId==$_POST['txtUserId']) && ($password==$_POST['txtPassword'])) {

// ID và password đúng,

// set session

$_SESSION['db_is_logged_in'] = true;

//set cookie

setcookie('UserCookie', $userId, time()+3600); /* hết hạn trong 1 giờ */

// sau khi login thì chuyển qua admin.php

header('Location: admin.php');

exit;

} else {

$errorMessage = 'Sai id hoặc password, mời nhập lại';

}

}

?>

<html>

<head>

<title> dang nhap</title>

<body>

<?php

if ($errorMessage != '') {

echo $errorMessage;

}

?>

<form action="<?php echo $_SERVER['file:///D|/Bai 1/PHP_SELF'];?>" method="post" name="frmLogin" id="frmLogin">

<table width="400" border="1" align="center" cellpadding="2" cellspacing="2">

<tr>

<td width="150">User Id</td>

<td><input name="txtUserId" type="text" id="txtUserId"></td>

</tr>

<tr>

<td width="150">Password</td>

<td><input name="txtPassword" type="password" id="txtPassword"></td>

</tr>

<tr>

<td width="150"> </td>

<td><input name="btnLogin" type="submit" id="btnLogin" value="Login"></td>

</tr>

</table>

</form>

</body>

</html>

</body>

</html>

Bạn đang đọc truyện trên: Truyen2U.Pro