简体   繁体   中英

Control access to class

I am using a class and functions for a controller.
Consider the following URL:

http://localhost:8888/mvc/user/profile/1

The class is user and the function is profile.
What is the best technique for someone going to

http://localhost:8888/mvc/user/random

and getting redirected elsewhere if the function isn't present?
As I'm unsure about this, I don't know what extra information you may need?

create htaccess with

//Custom 404 errors
ErrorDocument 404 http://localhost:8888/mvc/user/profile/1

You will get more details about .htaccess from here

Why not use php itself ?

if(!function_exists($function)){
 return header("HTTP/1.0 404 Not Found");
}

You can also redirect with the header function. So you can also add more logic if needed without having to depend on .htaccess or som other mechanism.

使用神奇的方法__call()处理任意方法调用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM