PHP中怎么实现全站权限验证,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册、虚拟主机、营销软件、网站建设、贵港网站维护、网站推广。
PHP全站权限验证代码示例:
< html>
< head>< title>e
< /title>
< /head>
< body>
< form action="login.php"
method="POST" >
用户:
< input type="text"
name="username">
< br>
密码:
< input type="password"
name="password">
< input type ="Submit"
value ="确定">
< input type ="reset"
value ="取消">
< /form>
< /body>
< /html>
----------------conn.php--------------------------
< ?php
$host='127.0.0.1';
$MySQL_user='root';
$mysql_password='qeephp';
$mydb='learn';
$link = mysql_connect($host,
$mysql_user , $mysql_password)
or die("无法连接数据库: "
. mysql_error());
mysql_select_db($mydb);
?>
----------------------------login.php------------------
< ?
$username=$_POST['username'];
$password=$_POST['password'];
if ($username==""){
echo "< script language='javascript'>
alert('非法操作!'); location.href=
'index.php'; < /script>";exit;
}
require_once("conn.php");
$sql="SELECT * FROM admin where
username='$username'";$result=mysql_query($sql);
$row=mysql_fetch_array($result);
if ($row['username']==""){
echo "< script language='javascript'>
alert('用户名有误!'); location.href=
'index.php'; < /script>";exit;
}else if ($row['password']!=$password){
echo "< script language='javascript'>
alert('密码有误!'); location.href='index
.php'; < /script>";echo "密码有误";
exit;
}else{
session_start();
$_SESSION['user']=$username;
echo "< script language='javascript'>
alert('登陆成功!'); location.href=
'list.php'; < /script>";}
?>
------------------check.php--------------------
< ?
session_start();
if(! isset($_SESSION['user']))
{
echo "< script language='javascript'>
alert('非法操作!'); location.href=
'index.php'; < /script>";exit;
}else{
echo "欢迎".$_SESSION['user']
."登录系统";}
?>
---------------------list.php-----------------
< ?
include 'check.php';
?>
< html>
< head>
< script type="text/javascript"
src="player/swfobject.js">< /script>< /head>
< body>
< h4>单个文件播放:< /h4>
< p id="player1">< a href="
http://www.macromedia.com/go/
getflashplayer">获取播放器< /a> 观看电影< /p>< script type="text/javascript">
var s1 = new SWFObject("player/
flvplayer.swf","single","300","170","7");s1.addParam("allowfullscreen","true");
s1.addVariable("file","player/ad.flv");
s1.addVariable("image","player/preview.jpg");
s1.addVariable("width","300");
s1.addVariable("height","170");
s1.write("player1");
< /script>
< h4>playlist file, with different
colors:< /h4>< p id="player2">< a href="http:
//www.macromedia.com/go/getflashplayer">
Get the Flash Player< /a> to see this player.< /p>< script type="text/javascript">
var s2 = new SWFObject("player/flvplayer
.swf","playlist","300","312","7");s2.addParam("allowfullscreen","true");
s2.addVariable("file","player/playlist.xml");
s2.addVariable("displayheight","200");
s2.addVariable("backcolor","0x000000");
s2.addVariable("frontcolor","0xCCCCCC");
s2.addVariable("lightcolor","0x557722");
s2.addVariable("width","300");
s2.addVariable("height","312");
s2.write("player2");
< /script>
< /body>
< /html>
--------------------logout.php-------------------------
< ?php unset($_SESSION['user']); unset($_SESSION['password']); echo "注销成功"; ?>
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。