Tạo trang đăng nhập và kiểm tra thông tin người dùng trong cơ sở dữ liệu MySQL.
-
1. Tạo bảng thành viên
Truy vấn SQL trên cơ sở dữ liệu
- Tạo trang đăng nhập chính
- Kiểm tra thông tin đăng nhập - checklogin.php
- Đăng nhập thành công
login_success.php
Code:
- Đăng xuất - Logout.php Code:
Create table “members”
Code PHP:$link = mysql_connect("localhost","root","");
mysql_select_db("databasename",$link);
$query = "
CREATE TABLE 'members' (
'id' int(4) NOT NULL auto_increment,
'username' varchar(65) NOT NULL default '',
'password' varchar(65) NOT NULL default '',
PRIMARY KEY ('id')
) TYPE=MyISAM AUTO_INCREMENT=2 ;
–
// Dumping data for table ‘members’
–
INSERT INTO 'members' VALUES (1, 'kenh360', '1234');
INSERT INTO 'members' VALUES (2, 'bantinit', '1234');
INSERT INTO 'members' VALUES (3, 'joomlavina', '1234');";
mysql_query($query);
file main_login.php
Code:<table width="300" border="1" cellpadding="0" cellspacing="1" style="background:#CCCCCC;border:1px solid #cccccc;margin:auto;text-align:center;">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?php
ob_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name// Connect to server and select databse.
mysql_connect(”$host”, “$username”, “$password”)or die(”cannot connect”);
mysql_select_db(”$db_name”)or die(”cannot select DB”);// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);$sql=”SELECT * FROM $tbl_name WHERE username=’$myusername’ and password=’$mypassword’”;
$result=mysql_query($sql);// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 rowif($count==1){
// Register $myusername, $mypassword and redirect to file “login_success.php”
session_register(”myusername”);
session_register(”mypassword”);
header(”location:login_success.php”);
}
else {
echo “Wrong Username or Password”;
}ob_end_flush();
?>
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?><html>
<body>
Login Successful
</body>
</html>
<?
session_start();
session_destroy();
?>
Theo aiti-aptech.edu.vn
| Tìm hiểu hàm Function Header trong PHP < Lùi | Tiếp theo > Lập trình PHP - Tạo 1 shoutbox đơn giản |
|---|
- 10/06/2009 16:00 - Lập trình PHP - Đếm số người trực tuyến
- 09/06/2009 23:50 - Chuỗi (xâu) và các hàm xử lý chuỗi trong PHP
- 09/06/2009 16:53 - Hàm PHP: substr_compare
- 08/06/2009 22:24 - Lập trình PHP - Mã hóa file bằng md5
- 08/06/2009 22:18 - Tìm hiểu hàm Function Header trong PHP
- 03/06/2009 22:00 - Lập trình PHP - Tạo 1 shoutbox đơn giản
- 03/06/2009 18:24 - Chuyển hướng Redirection với Drop Down Menu
- 02/06/2009 18:02 - Class: PHP Ajax Voting system
- 09/05/2009 15:02 - Xây dựng lớp Cắt xâu HTML string trong Lập trình PHP
- 03/05/2009 12:01 - Sử dụng GD library để tạo hình ảnh xác thực ngẫu nhiên trong lập trình PHP
Download Game bóng đá PES8 Việt Nam
Tải game bóng đá FiFa 09
Tải game Dragon ball Z - 7 viên ngọc rồng
Tải Game Bóng Đá Pro Evolution Soccer 6 Việt Nam
Download PES 2011 patch Việt Nam PESVN
Tải Game Bóng Đá FIFA 2009 RIP 1 CD
Download Pro Evolution Soccer 2011
Download Game THE SIMS 3
Tải Game bóng đá PES 2009
Download PES 2011 demo
Thay đổi màn hình đăng nhập Windows 7 bằng tay
Một số hàm hay dùng trong JavaScript
Kiểm soát hoàn toàn trỏ chuột bằng bàn phím với NeatMouse
Choáng với concept của Windows Phone 8
Những đặc điểm ưu việt của Windows Phone
Ứng dụng gọi điện VoIP Viber sắp có mặt trên Windows Phone
Game Diablo 3 sắp có mặt trên Windows Phone Marketplace
37 trang css & xhtml web template miễn phí tuyệt đẹp
Những điều cơ bản cần biết về bàn phím chơi game - Gaming Keyboard
L.A. Noire: The Complete Edition - THETA [Full ISO/Action/2011] [13.37GB]
Download 7554 demo
Download Game PC, cập nhật liên tục (torrent)
PES 2012 ra mắt bản mở rộng đầu tiên vào 11/10
PES2012 - Full version - Ngôn ngữ và bình luận tiếng Anh
PES2012 - Blurry disable làm mịn đồ họa
PES 2011 PATCH 4.1 - TRANSFER UPDATE - RELEASED
Bộ sưu tập free PrestaShop Themes phần 3
Bộ sưu tập theme Prestashop miễn phí phần 2
Top 10 Free PrestaShop Themes
Download Prestashop 1.5
Download PrestaShop 1.4
Bổ sung Memcached vào PrestaShop 1.4
Hướng dẫn tích hợp Ngân Lượng vào PrestaShop
Sửa lỗi invalid carrier or no carrier selected trong PrestaShop
Cài đặt PrestaShop
Thiết kế giao diện PrestaShop Theme
Hướng dẫn cài đặt themes trong PrestaShop
Hướng dẫn cách thêm ngôn ngữ cho PrestaShop
Bộ sưu tập Giao diện Premium PrestaShop Themes chuyên nghiệp
Giới thiệu về website thương mại điện tử 2.0 Prestashop
10 smartphone “bom xịt” năm 2010
Pro Evolution Soccer 2010 - Sự trở lại của vị vua [RELOADED][PC Game]
Bài 1: Làm quen với hệ quản trị cơ sở dữ liệu Microsoft Access


