One question. If I got it right? You are trying to redirect autoroutes (routes that work by default in CI4 - url/controller/method). You can turn them off in Config/Routes.php and than $routes->setAutoRoute(false); so there is no need for UsersCheck.php?
@@daniel00120012 Yes there is! Just add route like this: $routes->get('/viewfolder/(:any)', 'YourController::yourmethod'); This will reroute all routes that are not configured to your controller. Check CodeIgniter docs about URI routing for more cool solutions. codeigniter.com/user_guide/incoming/routing.html#uri-routing
wow sir ur so great....I had spent whole day just for making secure authenticate login & logout process in Codeigniter 4 , unfortunately I could not find that where did I mistake. Now Finlay I have solved it by help of your video. Thanks a lot sir. Plz sir, Keep going to post more videos about Codeigniter 4..
I must to thank you so much Alex. CI4 manual is fantastic, but when i found your tutorials, oh, man, everything changed for me. NOTE: for the code to work (in my case), using CI version 404, i need to include this on filter functions after and before: $arguments = null. Otherwise, a fatal error. Thanks again :)
Thank you very much for the video and the tutorial I would like you to help us all with an idea of how to implement user groups or roles Excellent work, keep it up
overall filters are good to use.. but since u created Usercheck filter for User Controller , so do I have to create filters for every controller which I create only for authorized users? Can we not just check that within the controller's constructor itself? or what if we just define the methods in the controller without public access specifier, won't it stop from being directly accessed ?? what should be the efficient way of achieving it??
There are different ways to do it. and yes you can do that in controller as you mentioned. But filters is a bit cleaner way, and besides the usercheck you can create more complex checks in the filter even manipulate the request itself.
Great work ! I just would ask for a 6th video showing how to integrate this Login system, from the repo, into an already existing project. Not having a lot of experience on PHP and CodeIgniter, I don't find that task trivial or evident. Thank you Alex !!
Hello, the filter logic is also working as it defines the path, but when I open the controller file via index.php, it does not come into play. What can I do?
Thank you for the tutorials. Good way to get started. I noticed that in the profile page, when the user information is updated, the session() is not updated. I attempted to use the setUserSession() called out in the Users.php file but it is not available in the profile.php view. What is the best method of making the setUserSession() available to a view page? Also, what is your recommendation as to the best place to update the session() variable?
hi, I' m having some problem with the url, my progect is on a webserver, inside a folder (named igniter). I stell need to put the word "users" before "register" for exemple, I have also some problem with the word "public". do you have any suggestion? very good job, thanks
Great Series, really helpful to a novice like myself. Ive noticed is that when you update the first name in the profile. save and go to the dashboard the display name still shows the old name (variable not refreshing?) not sure what I missed, tried it in your git code and its the same (also the db seems to point to test06 in the .env) Also really liked the Blog series you did. Currently trying to combine the blog with this! Do you have a patreon?
Hi alex, I am using codeigniter 4.1.1. In my case the filters automatically running without define in /Config/Routes. When I define (['filter' => 'auth']) or not in routes, it automatically run the filter. Why it happen?
Hello Alex, i have used your code but and got some problem. I was deleting userCheck.php file because it just redirecting to second segment, right. But now I could not using routes.php to redirect some url that i want. Anything routes has no affect to url. Please answer this! Thanks.
Dear, I stuck here .. while cliking on Profile link after login. this is the error message. Call to undefined function set_value() , APPPATH\Views\profile.php at line 17. but the line 17 is this like..................
Hey Zahir, sounds like you did not load the form helper inside your profile method. Check that pls. If it will not fix the issue, check the GitHub link in the description and compare your code to mine. Let me know if that helps. Cheers!
hi Alex thanks for the great tutorial, how could you protect access from user to admin page , in other words when user is logged in how can I prevent him from accessing admin page using filters
When user logs in and you set the session, just add the isAdmin => 0 or 1 then you can specify in your filter that in order to access certain pages isAdmin must be 1
Hi Alex, based on the CI4 documentation, we can either use session destroy or stop where it says "You may also use the stop() method to completely kill the session by removing the old session_id, destroying all data, and destroying the cookie that contained the session id:". Surprisingly the user session is still there when I used stop. Wonder do you have any idea why and destroy or stop, which is better?
Thanks! this series was very clear! I'm just having one issue I can't figure out. The UsersCheck filter keeps redirecting me (like it did for you) but appending the '/' to the segment doesn't change that. It does it on every single page. Doesn't matter if I go to users/profile or directly /profile. It does it for / and /dashboard too. Here is my code: $uri = service('uri'); $segment = ''; if ($uri->getSegment(1) == 'users') { if ($uri->getSegment(2) == '') $segment = '/'; else $segment = '/' . $uri->getSegment(2); } return redirect()->to($segment);
hi, have you fixed it? if not, here is my code, it is working: public function before(RequestInterface $request, $arguments = null) { $uri = service('uri'); if ($uri->getSegment(1) == 'users') { if ($uri->getSegment(2) == '') { $uriSegment = '/'; } else { $uriSegment = $uri->getSegment(2); } return redirect()->to(base_url($uriSegment)); } }
Great tutorial - but you Can set setAutoRoute to false - then function UserCheck is not necessary. I have one question (its only my opinion - when i'm wrong tell me). You used many times class implementation (session()->). Is load class to variable not more effective? You load class everytime when use session(), but in variable ex. $session = session(); - only one time. Meanwhile great job - 10/10! Have a nice day.
Hey, Jezgar, @thesloveniaboy123 also already pointed it out, and, yes, you are correct about autoRouting. Now about session, I don't remember exactly, but if I was using multiple session() in one request then yes you are right, I should've created a variable. Good point!
Thank you Alex Lancer for your awesome CI4 tutorials. They really help a lot. I have however met one problem in this final part of User Login Tutorial. I am getting the following error : Fatal error: Declaration of App\Filters\UsersCheck::before(CodeIgniter\HTTP\RequestInterface $request) must be compatible with CodeIgniter\Filters\FilterInterface::before(CodeIgniter\HTTP\RequestInterface $request, $arguments = NULL) in /var/www/html/CodeIgniter/CodeIgniter4/LoginSystem/app/Filters/UsersCheck.php on line 9 Declaration of App\Filters\UsersCheck::before(CodeIgniter\HTTP\RequestInterface $request) must be compatible with CodeIgniter\Filters\FilterInterface::before(CodeIgniter\HTTP\RequestInterface $request, $arguments = NULL) How can I resolve this ? Thanks so much in advance.
Not all heroes wear capes. Thanks man, for being the hero that all programming noobs need!
I just finish the fifth video and want to say again 👍👍👍👍👍 thank you Alex.
One question. If I got it right? You are trying to redirect autoroutes (routes that work by default in CI4 - url/controller/method). You can turn them off in Config/Routes.php and than $routes->setAutoRoute(false); so there is no need for UsersCheck.php?
Nice. Did not see that one yet. Learning together. Thanks!
Is there a way to set that to false but also redirect? When I do that, it's giving me error that the route can't be found.
@@daniel00120012 Yes there is! Just add route like this: $routes->get('/viewfolder/(:any)', 'YourController::yourmethod'); This will reroute all routes that are not configured to your controller. Check CodeIgniter docs about URI routing for more cool solutions. codeigniter.com/user_guide/incoming/routing.html#uri-routing
@@AlexLancer If i had seen this comment earlier. I could have saved 6 hours of my life. :|
Great series, Alex! The only thing I was hoping to hear more on is the sanitizing of user input and best practices doing that with CI4.
wow sir ur so great....I had spent whole day just for making secure authenticate login & logout process in Codeigniter 4 , unfortunately I could not find that where did I mistake. Now Finlay I have solved it by help of your video. Thanks a lot sir. Plz sir, Keep going to post more videos about Codeigniter 4..
You are most welcome. Glad that my video helped you to solve your problem.
Thank you so much bro
Thank you Alex for your time to create this series.
I must to thank you so much Alex. CI4 manual is fantastic, but when i found your tutorials, oh, man, everything changed for me. NOTE: for the code to work (in my case), using CI version 404, i need to include this on filter functions after and before: $arguments = null. Otherwise, a fatal error. Thanks again :)
Thank you Alex, those tutorials will help me during my internship
Great tutorial. It really helped me to get into CI4. Looking forward to explore your other tutorials as well!
Thank you very much for the video
and the tutorial
I would like you to help us all with an idea of how to implement user groups or roles
Excellent work, keep it up
What a great idea. That would surely be so damn helpful. I am in love with your comment.
overall filters are good to use.. but since u created Usercheck filter for User Controller , so do I have to create filters for every controller which I create only for authorized users?
Can we not just check that within the controller's constructor itself?
or what if we just define the methods in the controller without public access specifier, won't it stop from being directly accessed ??
what should be the efficient way of achieving it??
There are different ways to do it. and yes you can do that in controller as you mentioned. But filters is a bit cleaner way, and besides the usercheck you can create more complex checks in the filter even manipulate the request itself.
Same here, thank you so much for your tutorials. You saved me from a 28K files App folder from another popular framework =)
Great work !
I just would ask for a 6th video showing how to integrate this Login system, from the repo, into an already existing project.
Not having a lot of experience on PHP and CodeIgniter, I don't find that task trivial or evident.
Thank you Alex !!
Hey Alex, I'm new into visual studio code. can you make a separate video about what visual studio code extension you use?
Hey Ryan, I will do at some point yes. Not these days, but will do for sure.
A great series of videos! Thank you for your time
Thanks for watching.
Hello, the filter logic is also working as it defines the path, but when I open the controller file via index.php, it does not come into play. What can I do?
Thank you for the tutorials. Good way to get started.
I noticed that in the profile page, when the user information is updated, the session() is not updated.
I attempted to use the setUserSession() called out in the Users.php file but it is not available in the profile.php view. What is the best method of making the setUserSession() available to a view page? Also, what is your recommendation as to the best place to update the session() variable?
Thank you for doing these tutorials.
I'm new to codeigniter and these videos help alot. Easy to follow and understand :)
Glad you like them! And thanks for the comment.
Dei a sorte de pesquisar um dia depois de você ter publicado, gosto de tutoriais assim, objetivos, sem frescura. Parabéns, vou acompanhar o canal!
Obrigado pela ajuda. :)
I was stuck with the same segment access issue!!! thanks for this video ...
hi, I' m having some problem with the url, my progect is on a webserver, inside a folder (named igniter). I stell need to put the word "users" before "register" for exemple, I have also some problem with the word "public". do you have any suggestion? very good job, thanks
Thank you very much Alex, those tutorials are wonderful.
thx u alex for ur video.. i want to ask how to supply parameter to be passed to the filter's?
hi, i have a question, is there a way of putting to filters? something like ['filter'=>'rolauth','auth']);
Thank you al the way from The Republic of Philippines :)
Thank You Alex.
I have benefited a lot from this tutorial of yours.
Great Series, really helpful to a novice like myself.
Ive noticed is that when you update the first name in the profile. save and go to the dashboard the display name still shows the old name (variable not refreshing?) not sure what I missed, tried it in your git code and its the same (also the db seems to point to test06 in the .env)
Also really liked the Blog series you did. Currently trying to combine the blog with this! Do you have a patreon?
Just add "return redirect()->to('/profile');" to redirect to same page, and load updated data + flash message.
@@PavelTajdus3D cheers :)
Hi alex, I am using codeigniter 4.1.1. In my case the filters automatically running without define in /Config/Routes. When I define (['filter' => 'auth']) or not in routes, it automatically run the filter. Why it happen?
Sorry it was fixed. It's caused by defining the filter to $global in FIlters.php
When you built the dashboard, didn't you put in ['firstname'] ' ' ['lastname'] but we only see the first name 'Alex'?
Thanks for the series. Returning to part 1 now until I can do it all by myself
Good approach, Glenn.
Hello Alex, i have used your code but and got some problem. I was deleting userCheck.php file because it just redirecting to second segment, right. But now I could not using routes.php to redirect some url that i want. Anything routes has no affect to url. Please answer this! Thanks.
Dear, I stuck here .. while cliking on Profile link after login. this is the error message. Call to undefined function set_value() , APPPATH\Views\profile.php at line 17. but the line 17 is this like..................
Hey Zahir, sounds like you did not load the form helper inside your profile method. Check that pls.
If it will not fix the issue, check the GitHub link in the description and compare your code to mine. Let me know if that helps. Cheers!
@@AlexLancer Thank you very much...... form helper Solved the issue.... Cheers !!!
hi Alex thanks for the great tutorial, how could you protect access from user to admin page , in other words when user is logged in how can I prevent him from accessing admin page using filters
When user logs in and you set the session, just add the isAdmin => 0 or 1
then you can specify in your filter that in order to access certain pages isAdmin must be 1
Really enjoyed the tutorial Alex!
Hi Alex, based on the CI4 documentation, we can either use session destroy or stop where it says "You may also use the stop() method to completely kill the session by removing the old session_id, destroying all data, and destroying the cookie that contained the session id:". Surprisingly the user session is still there when I used stop. Wonder do you have any idea why and destroy or stop, which is better?
I want to add roles, how would it be?
your hard work is much appreciated. Thank you so much!
Can u provide acl
Access control system
Permission based
nice tutorial. Easy to understand
Glad you think so!
Hi Alex, Thank you for this very informative tutorial.
Another great video!Maybe one suggestion. It would maybe be better to name Noauth to for example "Guest".
At least you are watching and if you come up with suggestions it means that you like to code. I appreciate it.
You can close autorouting in route config to protect your routes.
You are a real super hero bro, thanks.
Thanks! this series was very clear! I'm just having one issue I can't figure out. The UsersCheck filter keeps redirecting me (like it did for you) but appending the '/' to the segment doesn't change that. It does it on every single page. Doesn't matter if I go to users/profile or directly /profile. It does it for / and /dashboard too. Here is my code:
$uri = service('uri');
$segment = '';
if ($uri->getSegment(1) == 'users')
{
if ($uri->getSegment(2) == '')
$segment = '/';
else
$segment = '/' . $uri->getSegment(2);
}
return redirect()->to($segment);
hi, have you fixed it? if not, here is my code, it is working:
public function before(RequestInterface $request, $arguments = null) {
$uri = service('uri');
if ($uri->getSegment(1) == 'users') {
if ($uri->getSegment(2) == '') {
$uriSegment = '/';
} else {
$uriSegment = $uri->getSegment(2);
}
return redirect()->to(base_url($uriSegment));
}
}
Great tutorial - but you Can set setAutoRoute to false - then function UserCheck is not necessary.
I have one question (its only my opinion - when i'm wrong tell me). You used many times class implementation (session()->).
Is load class to variable not more effective? You load class everytime when use session(), but in variable ex. $session = session(); - only one time.
Meanwhile great job - 10/10! Have a nice day.
Hey, Jezgar, @thesloveniaboy123 also already pointed it out, and, yes, you are correct about autoRouting.
Now about session, I don't remember exactly,
but if I was using multiple session() in one request then yes you are right, I should've created a variable.
Good point!
Thank you Alex 😃
Thanks for awesome tutorial ! You introduce me into CI4 !
Rafat, glad to hear that!
go ahead, wait for next part
Thanks.
Great Great Great..Alex
Awesome Tutorial!!,
Terimakasih Alex.
Thanks
Should I really learn ci4
Thank you Sir for this amazing tutorial 👍👍
super helpful tutorials! thank you.
Wonderful
Thank you
Thank you so much for this sir. Kudos!
God bless you 🎉🎉🎉🎉❤
thank you for your time :)
Thanks info. great series
Great selfless service 👍
it's a good tutorial for ci 4 starters
Thank you very much for this!
Thank you Alex Lancer for your awesome CI4 tutorials. They really help a lot.
I have however met one problem in this final part of User Login Tutorial. I am getting the following error :
Fatal error: Declaration of App\Filters\UsersCheck::before(CodeIgniter\HTTP\RequestInterface $request) must be compatible with CodeIgniter\Filters\FilterInterface::before(CodeIgniter\HTTP\RequestInterface $request, $arguments = NULL) in /var/www/html/CodeIgniter/CodeIgniter4/LoginSystem/app/Filters/UsersCheck.php on line 9
Declaration of App\Filters\UsersCheck::before(CodeIgniter\HTTP\RequestInterface $request) must be compatible with CodeIgniter\Filters\FilterInterface::before(CodeIgniter\HTTP\RequestInterface $request, $arguments = NULL)
How can I resolve this ? Thanks so much in advance.
Very useful ! Thanks
Thank very nice.. I learned a lot!
Wonderful!!
thank you alex
God bless you
Thank you for tutorial.
Thank you, sir.
thank you sir
Thanks for this.....you saved me
Afo, You are welcome!
❤
Cara favor faz um video com upload e rezise de imagens.
I will upload an image upload tutorial on this playlist shorturl.at/lrHRS next week. Stay tuned
i love you
Very informative, thanks, i learning so much !