C:\wamp\www\DEVOPS\Home\Lib\Action:

<?php
class IndexAction extends Action {
function index(){
$this->display();
} function do_login(){
//获取用户名和密码信息,和数据库中比对
echo 111111111;
dump($_POST);
dump($_SESSION);
echo 222222222;
$username=$_POST['username'];
$password=$_POST['password'];
$code=$_POST['code'];
#$this->display();
if($_SESSION['verify']!==md5($code)){
$this->error('验证码错误');
} $m=new Model('user');
$where['username']=$username;
$where['password']=md5($password); $arr = $m->where($where)->find(); $i=$m->where($where)->count(); if ($i>0){
$_SESSION['username']=$username;
$_SESSION['authority'] = $arr['authority'];
#$this->redirect('Main/index');
}else{
$this->error('该用户不存在');
}
} function checkUser(){
$username=$_POST['username'];
$m=new Model('user');
$where['username']=$username;
$i=$m->where($where)->count();
if ($i>0){
echo "1";
}else{
echo "0";
}
} function checkPasswd(){
$username=$_POST['username'];
$password=$_POST['password']; $m=new Model('user');
$where['username']=$username;
$where['password']=md5($password);
$i=$m->where($where)->count();
if ($i>0){
echo "1";
}else{
echo "0";
}
} function checkCode(){
$code=$_POST['code'];
if($_SESSION['verify']!==md5($code)){
echo "0";
}else{
echo "1";
}
}
}
?> Index模块下的index方法,调用前台模板 <html>
<head>
<title>Index</title>
<link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/Index/index.css'/>
</head>
<body>
<h1>中均运维管理平台</h1>
<!--图片标签-->
<img class="img_bk" src="__PUBLIC__/Images/scan.jpg"/>
<!--表单提交-->
<form action='__URL__/do_login' method='post' name="myForm">
<table cellspacing="0" cellpadding="0">
<tr>
<td class="td1">用户名:</td>
<td><input type="text" name="username"/></td>
<td class="td3"></td>
<td class="td4"></td>
<tr/>
<tr>
<td class="td1">密码:</td>
<td><input type="password" name="password"/></td>
<td class="td3"></td>
<td class="td4"></td>
<tr/>
<tr>
<td class="td1">验证码:</td>
<td> <input type='text' name='code' /></td>
<td class="td3"><img src="__APP__/Public/code" onclick='this.src=this.src+"?"+Math.random()'/></td>
<td class="td4"></td>
</tr>
<tr>
<td class="td1"></td>
<td><input type="button" value="" name="imgLogin"/></td>
<td class="td3"></td>
<td class="td4"></td>
</tr>
</table>
</form>
</body>
<script type="text/javascript" src="__PUBLIC__/Js/jquery-2.2.2.min.js"></script>
<script src="__PUBLIC__/Js/Index/index.js"></script>
<script src="__PUBLIC__/Js/Public/ajax.js"></script>
</html> 前台模板调用_URL__/do_login 等价于/DEVOPS/index.php/Index/do_login <form action="/DEVOPS/index.php/Index/do_login" method="post" name="myForm"> 那么怎么判断菜单访问页面前,判断登录呢? http://localhost/DEVOPS/index.php/Test/index 测试 此时可以直接访问: <?php
class TestAction extends Action{
// function _before_index(){
// if(!isset($_SESSION['username']) || $_SESSION['username']=='')
// {
// $this->redirect('Index/index');
// }
// } public function index(){
$this->display();
}
}; 此时跳过登录检查,那么怎么判断登录呢? //********************************* 前置和后置操作上一页下一页系统会检测当前操作是否具有前置和后置操作,如果存在就会按照顺序执行,前置和后置操作的方法名是在要执行的方法前面加 _before_和_after_,例如:
class CityAction extends Action{
//前置操作方法
public function _before_index(){
echo 'before<br/>';
}
public function index(){
echo 'index<br/>';
}
//后置操作方法
public function _after_index(){
echo 'after<br/>';
}
}
如果我们访问
http://serverName/index.php/City/index
结果会输出 before
index
after <?php
class TestAction extends Action{
function _before_index(){
if(!isset($_SESSION['username']) || $_SESSION['username']=='')
{
$this->redirect('Index/index');
}
} public function index(){
$this->display();
}
}; 此时会跳转到登录页 /*********** 打印信息: <?php
class TestAction extends Action{
function _before_index(){
var_dump($_SESSION);
#echo $_SESSION;
if(!isset($_SESSION['username']) || $_SESSION['username']=='')
{
#$this->redirect('Index/index');
}
} public function index(){
$this->display();
}
}; 此时访问http://localhost/DEVOPS/index.php/Test/index: array (size=1)
'verify' => string '8289889263db4a40463e3f358bb7c7a1' (length=32) test 20160707 scan! 可以看到 $_SESSION['username'] 为空 如果登录的话SESSION里的信息为: array (size=3)
'verify' => string '198dd5fb9c43b2d29a548f8c77e85cf9' (length=32)
'username' => string 'admin' (length=5)
'authority' => string '1' (length=1)

php使用 _before_index() 来实现访问页面前,判断登录的更多相关文章

  1. php 用户访问菜单页面,必须登录,判断用户是否登录

    <pre name="code" class="python"># 本节课大纲: 一.空模块和空操作 1.空操作 function _empty($ ...

  2. 前段时间,接手一个项目使用的是原始的jdbc作为数据库的访问,发布到服务器上在运行了一段时间之后总是会出现无法访问的情况,登录到服务器,查看tomcat日志发现总是报如下的错误。    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected est

    前段时间,接手一个项目使用的是原始的jdbc作为数据库的访问,发布到服务器上在运行了一段时间之后总是会出现无法访问的情况,登录到服务器,查看tomcat日志发现总是报如下的错误. Caused by: ...

  3. Ant Design Pro项目打开页设为登录或者其他页面

    Ant Design Pro项目打开页设为登录或者其他页面 一.打开页设为登录页 首先找到utils包中的authority文件,在该文件中找到如下代码: export function getAut ...

  4. 不同项目同一浏览器访问 导致Session覆盖 登录后点击就退出登录问题

    产生原因:最近开发项目两个项目部署采用同一个tomcat 部署  (当两个tomcat部署时也会产生)由于部署时候两个项目访问域名相同  localhost:8080/     localhost:8 ...

  5. 用curl访问HTTPS站点并登录

    开发网站,少不了测试.现在的网站为了加强安全性,都启用了HTTPS协议.所谓HTTPS,也就是HTTP文本在SSL协议中传输.用curl命令行来测试HTTPS站点是个很有用的功能,写点脚本,就可以做功 ...

  6. 禁止ajax访问shiro管理的登录页面

    在使用shiro的时候,对于用户权限的管理,相信很多人都已经很熟悉了.今天,我这里简单的记录一下我自己调试过程中遇到的问题.主要是登录的操作,禁止通过ajax的方式进行访问. shiro中,登录过程拒 ...

  7. Android检查设备是否可以访问互联网,判断Internet连接,测试网络请求,解析域名

    安卓SDK提供了ConnectivityManager类,那么我们就可以轻松的获取设备的网络状态以及联网方式等信息. 但是要想知道安卓设备连接的网络能不能访问到Internet,就要费一番周折了. 本 ...

  8. 【Loadrunner】通过loadrunner录制时候有事件但是白页无法出来登录页怎么办?

    loadrunner录制脚本时候有事件但是一直白页怎么办? 解决办法:依次进行下方1.2.方法操作,如果还不行再进行3的操作. 1.勾选下图IE浏览器的Internet选项中“启用第三方浏览器拓展*” ...

  9. 用curl访问HTTPS站点并登录(对HTTP返回的结果特别清楚)

    开发网站,少不了测试.现在的网站为了加强安全性,都启用了HTTPS协议.所谓HTTPS,也就是HTTP文本在SSL协议中传输.用curl命令行来测试HTTPS站点是个很有用的功能,写点脚本,就可以做功 ...

随机推荐

  1. 正确的 zip 压缩与解压代码

    网上流传的zip压缩与解压 的代码有非常大的问题 尽管使用了ant进行压缩与解压,可是任务的流程还是用的java.util.zip 的方式写的,我在使用的过程中遇到了压缩的文件夹结构有误,甚至出现不同 ...

  2. 修改字符串 ToCharArray()

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. c++, 虚基派生 : 共同基类产生的二义性的解决办法

    虚基派生 //虚继承 #include <iostream> using namespace std; #include <string> //---------------- ...

  4. __get __set 实例

    <?php class Person { //下面是人的成员属性,都是封装的私有成员 private $name; //人的名子 private $sex; //人的性别 private $ag ...

  5. WinXP系统服务详细列表

    windows XP 系统服务“关闭”详细列表,释放N多内存,128也够用了! 在xp系统中,有近90个服务,默认开启了 30多个服务,而事实上我们只需要其中几个就够用了.禁止所有不必要的服务可以为您 ...

  6. JMS和消息驱动Bean(MDB)

    一.说明 本示例使用的ActiveMQ作为消息中间件,服务器为Glassfish,使用JMS发送消息,在MDB接收到消息之后做打印输出. 二.ActiveMQ安装配置 1.安装console war包 ...

  7. MFC全局函数开局——AfxGetApp解剖

    MFC中有不少的全局函数,方便在不同对象中获取不同的内容或创建不同的对象.主要全局函数有: AfxWinInit() AfxBeginThread() AfxEndThread() AfxFormat ...

  8. matlab绘图方法汇总

    Matlab画图 强大的画图功能是Matlab的特点之中的一个,Matlab提供了一系列的画图函数,用户不须要过多的考虑画图的细节,仅仅须要给出一些基本參数就能得到所需图形,这类函数称为高层画图函数. ...

  9. 动态规划之一ones

    n给一个整数n,要你找一个值为n的表达式,这个表达式只有1 + * ( ) 够成.并且1不能连续,比如11+1就不合法. n输入n,(1<=n<=10000) n输出最少需要多少个1才能构 ...

  10. 13 - NSURLConnection

    一.互联网 基本概念: HTTP协议 统一标准获取网络资源(其他设备上的东西) 本机 -> 远程服务器(计算机) URL(http有格式的字符串) 本机 <- 远程服务器(计算机) Fil ...