thinkphp NULL controller and NULL operation and corresponding solution

Source: Internet
Author: User

Null operation: An object (Controller) Call method that does not exist by itself

NULL controller: The specified class was not found when instantiating the Controller object

First, create a new Ceshi module under the application file and follow the home module under the Ceshi module to create the same folder, such as:

1) Create a new login controller under the Controller folder:

<?phpnamespace ceshi\controller;use think\controller;class Logincontroller extends  controller{   public function login ()   {    echo] Welcome to login! ";   }}

2) Address bar input access address: Http://localhost/wamp/thinkphp/index.php/Ceshi/Login/login

First, the address bar to access the non-existent method, what happens?

Http://localhost/wamp/thinkphp/index.php/Ceshi/Login/loginSSS

From this page, we can know:

(1) This interface exposes the code we use to write the tool and exposes the thinkphp version number, which can be exploited if the hacker finds a bug in the version number.

(2) Second, this interface is very unfriendly, for users, they do not understand and do not know what is wrong.

How to give a more secure, more friendly hint?

There is a method in the parent class that we can do with this:

The first method: Make an empty template

1) Create a Ceshi folder under the View folder with the following path:

Loginsss.html

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

2) Visit Http://localhost/wamp/thinkphp/index.php/Ceshi/Login/loginsss again

This is much more friendly than just the code, but it is not possible to make a template every time we enter a non-existent method, which is impractical, and we don't know what the user will be typing next, so this method is not feasible.

The second method: Do an empty method: _empty () method

<?phpnamespace ceshi\controller;use think\controller;class Logincontroller extends  controller{   public function login ()   {    echo] Welcome to login! ";   }   Public Function _empty () {    echo] The action method you accessed does not exist! ";   }}

 

This way, no matter what kind of empty method you access, you will see "The action method you accessed does not exist!" ”

http://localhost/wamp/thinkphp/index.php/Ceshi/Login/Logins

Http://localhost/wamp/thinkphp/index.php/Ceshi/Login/aaa

Second, in the address bar to access the non-existent controller, what happens? The same error occurred

Workaround:

Create a new empty controller:

EmptyController.class.php

<?phpnamespace ceshi\controller;use think\controller;class Emptycontroller extends controller{public    function _empty () {        echo "the controller you have accessed is wrong";    }}

Re-visit http://localhost/wamp/thinkphp/index.php/Ceshi/Main/login

Change a http://localhost/wamp/thinkphp/index.php/Ceshi/mmmn/login

This will solve the problem of NULL controller and empty operation ~.~.~

 

 

thinkphp NULL controller and NULL operation and corresponding solution

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.