php实实现现购购物物车车功功能能 ((下下))
接着上篇继续学习: 《《php实实现现购购物物车车的的功功能能 ((上上))》》
7、实现一个管理界面
登登录录界界面面
以下代码实现:
7.1 admin.php
/**
* @author switch
* @copyright 2015
* 主管理菜单
*/
//require_once语句和require语句完全相同,唯一区别是PHP会检查该文件是否已经被包含过,如果是则不
会再次包含。
require_once( book_sc_fns.php );
session_start();
if((@$_POST[ username ]) && (@$_POST[ passwd ])) //尝试登陆
{
$username = $_POST[ username ];
$passwd = $_POST[ passwd ];
if(login($username,$passwd))
{
$_SESSION[ admin_user ] = $username;
}
else
{
do_html_header("Problem:");
echo "
You could not be logged in.
You must be logged in to view this page.
";do_html_URL( login.php , Login );
do_html_footer();
exit;
}
}
do_html_header("Administration");
if(check_admin_user())
{
display_admin_menu();
}
else
{
echo "
You are not authorized to enter the administration area.
";do_html_URL( login.php , Login );
}
do_html_footer();
?>
7.2 user_auth_fns.php文件中的函数login()
function login($username,$password) //登录
{
$conn = db_connect(); //连接数据库
if(!$conn)
return 0;
//检查用户名唯一性
$query = "select * from admin where username= ". $username ."
and password = sha1( ". $password ." )";
$result = $conn ->query($query);
if(!$result)
return 0;
if($result ->num_rows > 0)
return 1;
else
return 0;