Direct Access prohibited from public modules

Source: Internet
Author: User
Provides various official and user-released code examples and code reference. You are welcome to share some common methods or variables in your learning projects in a single module, called a public module.
The public module directly inherits the Action class, and other modules inherit the public module.
So how can we prevent public modules from being directly accessed externally?
For example, a public module CommonAction is defined. class CommonAction extends Action {
public $uid;
……
}
Other modules: Class UserAction extends CommonAction {
Function index (){
Echo $ this-> uid; // you can directly use public variables here
}
......
}
However, if an operation is defined in CommonAction and is not processed, the visitor can directly use/index. php/Common/operation name.
In general, public modules do not require direct access from visitors.
In this case, you only need to make a simple process.

1. In the UserAction. class. php file: Define ("INC", 1); // defines INC Constants
Class UserAction extends CommonAction {
......
}
?>
2. In CommonAction. class. php: // Determine whether there is a defined INC. If not, exit directly.
If (! Defined ("INC ")){
Exit ('Access Denied ');
}
Class CommonAction extends Action {
......
}
?>

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.