How do I make a database row be a global? |
How do I make a database row be a global?
I've used google search for answers and none of the results helped me. I am using this tutorial. Here is config/globals.php Code: <?php Here are the errors I get. Undefined property: CI_Loader::$load on Line 7 Call to a member function database() on null on Line 7 Is there a good way of making a database row a global? I am writing my own authentication system as Codeigniter doesn't come with one.
First, use one of the already built and tested authentication systems out there. (don't reinvent the wheel...)
Second, create a MY_controller that all of the rest of your controllers inherit from, in the constructor, you can setup a call to your authentication methods. Since the system is "setup" at this point, the loading for the databases will work and everything will work as expected (just don't forget to inherit all of the controllers needing authentication to the MY_controller)
I've worked on extending a core class to do this in core/Before.php
Code: <?php The website does not terminate despite the 2 exit() existing. I have a controller in controllers/Admin.php with a class called Admin. When I try to echo $me in the view, I get an error saying that $me is undefined. Please help.
PHP Code: <?php Then in your controller: PHP Code: public function somefunc() {
Please escape your users input. Cookie data can be manipulated and you are vulnarable to sql injection. You should read up on php (basic) security
(06-26-2017, 10:56 AM)Diederik Wrote: Please escape your users input. Cookie data can be manipulated and you are vulnarable to sql injection. You should read up on php (basic) security @Diederik, desbest is a security expert. </sarcasm> desbest a you a college student or do you work for a company? use remember me token use escape_str from ci use $id = (int) $id; (06-26-2017, 08:41 PM)Paradinight Wrote:(06-26-2017, 10:56 AM)Diederik Wrote: Please escape your users input. Cookie data can be manipulated and you are vulnarable to sql injection. You should read up on php (basic) security I'm a college student. I did go to Security Stack Exchange and r/forhire for security help but no one could help me sufficiently. Also the php escaping functions such as mysqli_real_escape_string and php prepared statements can be bypassed very easily, so a server firewall provides much better protection against sql injection than php. Also when I asked people if they knew how to make an authentication system, they didn't know and some were reluctant to say no, their answer was, use Laravel's authentication system, use Laravel. (06-26-2017, 10:28 AM)Kaosweaver Wrote:I did that but I still get the same error. Undefined property: Admin::$me I would like a database row to be accessible from all controllers.
Then you need to create ./application/core/MY_Controller.php
Then extend all of your controllers from that one. PHP Code: <?php What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
I've done the instructions you said. When I use print_r($me); in MY_Controller.php which extends CI_Controller, I can see the $me variable on the screen. However the $me variable isn't passed to all the controllers such as Admin.php "class Admin extends MY_Controller". When I echo or use $me on Admin.php controller I get an error saying $me is undefined.
|
Welcome Guest, Not a member yet? Register Sign In |