Home Backend Development PHP Tutorial Teach you how to quickly implement PHP site-wide authority verification_PHP Tutorial

Teach you how to quickly implement PHP site-wide authority verification_PHP Tutorial

Jul 15, 2016 pm 01:34 PM
head html php title code accomplish fast teach you Permissions Example verify

PHP site-wide authority verification code example:

  1. < html>
  2. < head> < title> e
  3. < /title >
  4. < /head>
  5. < body>
  6. < form action="login.php"
    method="POST" >

User:

  1. < input type="text"
    name= "username">
  2. < br>

Password:

  1. < input type="password" 
    name="password"> 
  2. < input type ="Submit"
     value ="确定"> 
  3. < input type ="reset"
     value ="取消"> 
  4. < /form> 
  5. < /body> 
  6. < /html> 

----------------conn.php--------------------------

  1. < ?php  
  2. $host='127.0.0.1';  
  3. $mysql_user='root';  
  4. $mysql_password='qeephp';  
  5. $mydb='learn';  
  6. $link = mysql_connect($host, 
    $mysql_user , $mysql_password)  
  7. or die("无法连接数据库: " 
    . mysql_error());  
  8. mysql_select_db($mydb);  
  9. ?> 

----------------------------login.php------------------

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?  </span></span></li><li><span>$</span><span class="attribute">username</span><span>=$_POST['username'];  </span></li><li class="alt"><span>$</span><span class="attribute">password</span><span>=$_POST['password'];  </span></li><li><span>if ($</span><span class="attribute">username</span><span>==""){  </span></li><li class="alt"><span>echo "</span><span class="tag"><</span><span> </span><span class="tag-name">script</span><span> </span><span class="attribute">language</span><span>=</span><span class="attribute-value">'javascript'</span><span class="tag">></span><span> <br>alert('非法操作!'); </span><span class="attribute">location.href</span><span>=<br></span><span class="attribute-value">'index.php'</span><span>; </span><span class="tag"><</span><span> /script</span><span class="tag">></span><span>";  </span></span></li>
<li><span>exit;  </span></li>
<li class="alt"><span>}  </span></li>
<li><span>require_once("conn.php");  </span></li>
<li class="alt">
<span>$</span><span class="attribute">sql</span><span>=</span><span class="attribute-value">"SELECT * FROM admin where<br> username='$username'"</span><span>;  </span>
</li>
<li>
<span>$</span><span class="attribute">result</span><span>=</span><span class="attribute-value">mysql_query</span><span>($sql);  </span>
</li>
<li class="alt">
<span>$</span><span class="attribute">row</span><span>=</span><span class="attribute-value">mysql_fetch_array</span><span>($result);  </span>
</li>
<li><span>if ($row['username']==""){  </span></li>
<li class="alt">
<span>echo "</span><span class="tag"><</span><span> </span><span class="tag-name">script</span><span> </span><span class="attribute">language</span><span>=</span><span class="attribute-value">'javascript'</span><span class="tag">></span><span> <br>alert('用户名有误!'); </span><span class="attribute">location.href</span><span>=<br></span><span class="attribute-value">'index.php'</span><span>; </span><span class="tag"><</span><span> /script</span><span class="tag">></span><span>";  </span>
</li>
<li><span>exit;  </span></li>
<li class="alt"><span>}else if ($row['password']!=$password){  </span></li>
<li>
<span>echo "</span><span class="tag"><</span><span> </span><span class="tag-name">script</span><span> </span><span class="attribute">language</span><span>=</span><span class="attribute-value">'javascript'</span><span class="tag">></span><span> <br>alert('密码有误!'); </span><span class="attribute">location.href</span><span>=</span><span class="attribute-value">'index<br>.php'</span><span>; </span><span class="tag"><</span><span> /script</span><span class="tag">></span><span>";  </span>
</li>
<li class="alt"><span>echo "密码有误";  </span></li>
<li><span>exit;  </span></li>
<li class="alt"><span>}else{  </span></li>
<li><span>session_start();  </span></li>
<li class="alt"><span>$_SESSION['user']=$username;  </span></li>
<li>
<span>echo "</span><span class="tag"><</span><span> </span><span class="tag-name">script</span><span> </span><span class="attribute">language</span><span>=</span><span class="attribute-value">'javascript'</span><span class="tag">></span><span> <br>alert('登陆成功!'); </span><span class="attribute">location.href</span><span>=<br></span><span class="attribute-value">'list.php'</span><span>; </span><span class="tag"><</span><span> /script</span><span class="tag">></span><span>";  </span>
</li>
<li class="alt"><span>}  </span></li>
<li>
<span class="tag">?></span><span> </span>
</li>
</ol>
Copy after login

------------------check.php--------------------

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?  </span></span></li>
<li><span>session_start();   </span></li>
<li class="alt"><span>if(! isset($_SESSION['user']))   </span></li>
<li><span>{   </span></li>
<li class="alt">
<span>echo "</span><span class="tag"><</span><span> </span><span class="tag-name">script</span><span> </span><span class="attribute">language</span><span>=</span><span class="attribute-value">'javascript'</span><span class="tag">></span><span> <br>alert('非法操作!'); </span><span class="attribute">location.href</span><span>=<br></span><span class="attribute-value">'index.php'</span><span>; </span><span class="tag"><</span><span> /script</span><span class="tag">></span><span>";  </span>
</li>
<li><span>exit;  </span></li>
<li class="alt"><span>}else{  </span></li>
<li><span>echo "欢迎".$_SESSION['user']<br>."登录系统";   </span></li>
<li class="alt"><span>}  </span></li>
<li>
<span class="tag">?></span><span> </span>
</li>
</ol>
Copy after login

---------------------list.php-----------------

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?  </span></span></li><li><span>include 'check.php';  </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li>
<li>
<span class="tag"><</span><span> </span><span class="tag-name">html</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span class="tag"><</span><span> </span><span class="tag-name">head</span><span class="tag">></span><span> </span>
</li>
<li>
<span class="tag"><</span><span> </span><span class="tag-name">script</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/javascript"</span><span> <br /></span><span class="attribute">src</span><span>=</span><span class="attribute-value">"player/swfobject.js"</span><span class="tag">></span><span class="tag"><</span><span> /script</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span class="tag"><</span><span> /head</span><span class="tag">></span><span> </span>
</li>
<li>
<span class="tag"><</span><span> </span><span class="tag-name">body</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span class="tag"><</span><span> </span><span class="tag-name">h3</span><span class="tag">></span><span>单个文件播放:</span><span class="tag"><</span><span> /h3</span><span class="tag">></span><span> </span>
</li>
<li>
<span class="tag"><</span><span> </span><span class="tag-name">p</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"player1"</span><span class="tag">></span><span class="tag"><</span><span> </span><span class="tag-name">a</span><span> </span><span class="attribute">href</span><span>=</span><span class="attribute-value">"<br />http://www.macromedia.com/go/<br />getflashplayer"</span><span class="tag">></span><span>获取播放器</span><span class="tag"><</span><span> /a</span><span class="tag">></span><span> 观看电影</span><span class="tag"><</span><span> /p</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span class="tag"><</span><span> </span><span class="tag-name">script</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/javascript"</span><span class="tag">></span><span> </span>
</li>
<li>
<span>var </span><span class="attribute">s1</span><span> = </span><span class="attribute-value">new</span><span> SWFObject("player/<br>flvplayer.swf","single","300","170","7");  </span>
</li>
<li class="alt"><span>s1.addParam("allowfullscreen","true");  </span></li>
<li><span>s1.addVariable("file","player/ad.flv");  </span></li>
<li class="alt"><span>s1.addVariable("image","player/preview.jpg");  </span></li>
<li><span>s1.addVariable("width","300");  </span></li>
<li class="alt"><span>s1.addVariable("height","170");  </span></li>
<li><span>s1.write("player1");  </span></li>
<li class="alt">
<span class="tag"><</span><span> /script</span><span class="tag">></span><span> </span>
</li>
<li>
<span class="tag"><</span><span> </span><span class="tag-name">h3</span><span class="tag">></span><span>playlist file, with different <br>colors:</span><span class="tag"><</span><span> /h3</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span class="tag"><</span><span> </span><span class="tag-name">p</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"player2"</span><span class="tag">></span><span class="tag"><</span><span> </span><span class="tag-name">a</span><span> </span><span class="attribute">href</span><span>=</span><span class="attribute-value">"http:<br />//www.macromedia.com/go/getflashplayer"</span><span class="tag">><br></span><span>Get the Flash Player</span><span class="tag"><</span><span> /a</span><span class="tag">></span><span> to see this player.</span><span class="tag"><</span><span> /p</span><span class="tag">></span><span> </span>
</li>
<li>
<span class="tag"><</span><span> </span><span class="tag-name">script</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/javascript"</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span>var </span><span class="attribute">s2</span><span> = </span><span class="attribute-value">new</span><span> SWFObject("player/flvplayer<br>.swf","playlist","300","312","7");  </span>
</li>
<li><span>s2.addParam("allowfullscreen","true");  </span></li>
<li class="alt"><span>s2.addVariable("file","player/playlist.xml");  </span></li>
<li><span>s2.addVariable("displayheight","200");  </span></li>
<li class="alt"><span>s2.addVariable("backcolor","0x000000");  </span></li>
<li><span>s2.addVariable("frontcolor","0xCCCCCC");  </span></li>
<li class="alt"><span>s2.addVariable("lightcolor","0x557722");  </span></li>
<li><span>s2.addVariable("width","300");  </span></li>
<li class="alt"><span>s2.addVariable("height","312");  </span></li>
<li><span>s2.write("player2");  </span></li>
<li class="alt">
<span class="tag"><</span><span> /script</span><span class="tag">></span><span> </span>
</li>
<li>
<span class="tag"><</span><span> /body</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span class="tag"><</span><span> /html</span><span class="tag">></span><span> </span>
</li>
</ol>
Copy after login

--------------------logout.php-------------------------

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php   </span></span></li><li><span>unset($_SESSION['user']);   </span></li><li class="alt"><span>unset($_SESSION['password']);   </span></li><li><span>echo "注销成功";   </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li></ol>
Copy after login

以上就是PHP全站权限验证的具体实现方法。


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445984.htmlTechArticlePHP full site authority verification code example: html head title e /title /head body form action = login.php method = POST user: input type = text name = username br password: input type =...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles