简体   繁体   English

如何使用Codeigniter制作更安全的登录系统?

[英]How to make more secure login system with codeigniter?

I want to make more secure login system with codeigniter. 我想用codeigniter制作更安全的登录系统。 I can make simple one with this example. 我可以用这个例子做一个简单的例子。

http://www.codefactorycr.com/login-with-codeigniter-php.html http://www.codefactorycr.com/login-with-codeigniter-php.html

But problem here is that with the example I can have direct access to "check_database" method from url address. 但是这里的问题是,通过示例,我可以从URL地址直接访问“ check_database”方法。 But I want to prevent it. 但我想防止这种情况。 So if user tries to get access to the method he will be redirected to login or welcome page. 因此,如果用户尝试访问该方法,则将其重定向到登录页面或欢迎页面。 Please note that I might have more than 10 methods. 请注意,我可能有10种以上的方法。 I don't want to configure them one by one. 我不想一个接一个地配置它们。 Do you have any solution? 你有什么解决办法吗?

Using a private function won't work. 使用私有功能将不起作用。

If you read the manual you can see you need to write the function with an _ before the function name. 如果您阅读了手册,您会看到您需要在函数名称之前用_编写函数。

So function check_database() becomes function _check_database() 因此, function check_database()变为function _check_database()

read here http://ellislab.com/codeigniter/user-guide/general/controllers.html#private 在这里阅读http://ellislab.com/codeigniter/user-guide/general/controllers.html#private

Include just after the method opening: 在方法打开之后立即添加:

if (!$this->input->post())
  redirect('somewherelse!');

So if there is nothing as POST request, someone trying to access it directly from URL. 因此,如果没有任何POST请求,则有人试图直接从URL访问它。

If might have more than 10 methods... 如果可能有十种以上的方法...

If all methods should just receive POST requests, then put it on __construct(), something like: 如果所有方法都应该只接收POST请求,则将其放在__construct()上,如下所示:

function __construct(){
  parent::__construct();

  if (!$this->input->post())
    redirect('somewherelse!');   
}

Alternatively you could make a custom library , which could have a CodeIgniter reference to use database, and there make all the login business, returning just true or false on logged status. 或者,您可以创建一个自定义库 ,该可以具有CodeIgniter引用以使用数据库,然后进行所有登录业务,并在登录状态下返回truefalse

Use Private Functions. 使用私有功能。 These wont be accessible via URL & will be hidden from public access 这些将无法通过URL访问,并且将被公共访问隐藏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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