Welcome Guest, Not a member yet? Register   Sign In
Few basic questions
#1

[eluser]bewhite[/eluser]
Hello!
I'm still noob in CI so don't be angry about my (stupid?) questions:

1)I will need to create very basic authentication functionality. I know about freak_auth but I don't want to use it because it is too complex for my case. I need to check the variable in the session each time when GET or POST recieved and before Controller method execution. If this variable will have wrong value (for current controller/action) then make redirect to the default page. As I understand, the best place to do this is front controller(CodeIgniter.php). Question: do I have access to the CI session and controller name at the front controller? Maybe, there is better way to organize this simple function?
2)I'm using CI on the Debian Linux with Apache 2.2 and Opera browser. Often pages are not changed after code was changed. I don't need caching in my project. How can I disable caching or make sure it is already disabled? Maybe, the problem is in Opera or Apache?
3)After redirect_to using I recieve url like http://site.com/index.php/controller/action. I have enabled mod_rewrite and I'm using simple format without index.php in all redirects. How can I remove 'index.php' from my urls?

Thanks.
#2

[eluser]xwero[/eluser]
1. there are a few libraries available for authentication including ErkanaAuth: A non-invasive user authentication library (not mine). The fastest way to set up a basic authentication is making a authentication model, autoload it or load it where it's needed and use the methods login, isUser, logout (if you named them like this).

2. I think it's more a opera problem, try to disable the caching
#3

[eluser]Gavin Vickery[/eluser]
Answer to #3:

You need to remove the 'index.php' in your URL Suffix. You can do this by opening up the config.php file located in system/application/config/ directory.

Change the line:
Code:
$config['url_suffix'] = "index.php";

To:
Code:
$config['url_suffix'] = "";
#4

[eluser]bewhite[/eluser]
[quote author="Gavin Vickery" date="1194561004"]
Code:
$config['url_suffix'] = "";
[/quote]
Perfect. Thanks.
#5

[eluser]bewhite[/eluser]
[quote author="xwero" date="1194546613"]1. there are a few libraries available for authentication including ErkanaAuth: A non-invasive user authentication library (not mine). The fastest way to set up a basic authentication is making a authentication model, autoload it or load it where it's needed and use the methods login, isUser, logout (if you named them like this). [/quote]
Actually, ErkanaAuth is too complex for my case. I don't need all this functionality. Instead of using library I have tryed to insert next code after 'Security check' section in CodeIgniter.php:
Code:
if(empty($_SESSION['user_id'])) redirect('/auth', 'location');
elseif(($_SESSION['user_id'] > 1) && ($class == 'admin')) redirect('/resources', 'location');
This should redirect user to the Auth module if user_id is not set before and redirect users to the public page if they have no admin(1) user_id value. As you see it is much more easy then all these libraries and it is exactly what I need.
Unfortunately, it is not working. As I see, both $_SESSION array and redirect function are not defined in this part of code. Can anybody tell me how I can use session values that were set by $this->session->set_userdata? How can I use redirect function inside CodeIgniter.php?

[quote author="xwero" date="1194546613"]2. I think it's more a opera problem, try to disable the caching[/quote]
Yes. It seems like problem was fixed after Opera caching was disabled.

Thanks.
#6

[eluser]bewhite[/eluser]
Problem was fixed by moving block of code under Controller object initialization and trasnforming of code to this:
Code:
$my_user_id = $CI->session->userdata('user_id');

if(empty($my_user_id) && ($class != 'auth')) redirect('/auth', 'location');
elseif(($my_user_id > 1) && ($class == 'admin')) redirect('/resources', 'location');

unset($my_user_id);

Thanks to all. Thread can be closed.
#7

[eluser]Michael Wales[/eluser]
Holy smokes... you are the first person to ever say ErkanaAuth was to complex! Big Grin

Your code (using Erkana) would be:
Code:
if ((!$this->erkanaauth->try_session_login) && ($class != 'auth')) redirect('auth');
elseif (($this->erkanaauth->try_session_login) && ($class == 'admin')) redirect('resources');

Really not much of a typing saver for you in this case, but I think it would save some time when you work on the login functionality of your app.




Theme © iAndrew 2016 - Forum software by © MyBB