How to avoid the code analysis of the user's direct access in PHP background

Source: Internet
Author: User
Tags yii
This article describes how the PHP background to avoid users directly into the method instance, the need for friends can refer to

1) Create Basecontroller controller to inherit controllers (all operations in the background to inherit Basecontroller):

Add in Basecontroller:

Public Function Checklogin () {         if (Yii::app ()->authority->islogin () = = Yii::app ()->authority-> GetStatus (' Notlogin ')) {             $url = $this->createurl (' User/login ');             if (Yii::app ()->request->ispostrequest && Yii::app ()->request->isajaxrequest) {                 echo Json_ Encode (Array (' code ' = + -101, ' message ' = ' = ' user not logged in. ', ' callback ' = ' window.location= '. $url. '";'));             } else if (Yii::app ()->request->isajaxrequest) {                 echo ' <script language= "JavaScript" >window.location= "' . $url. ';</script> ';             } else {                 $this->redirect ($url);             }             Exit;         }         return true;     }

Create the authority.php file in the components directory:

<?php/**  * Permissions Check Unit  */class Authority extends Ccomponent {     private $NOTLOGIN =-1;     Private $FAILED =-2;     Private $PASS = 1;     Public Function init () {     }     /**      * Check for login      * @return Boolean       *    /function IsLogin () {         Return Isset (Yii::app ()->session[' user ')? $this->pass: $this->notlogin;     }        /**      * Gets the status value      * @param string $name      * @return int *       /public    function GetStatus ($name) {         return $this $name;     } }

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.