Welcome Guest, Not a member yet? Register   Sign In
Login on top of every page?
#1

[eluser]Unknown[/eluser]
Hi guys
I'm building a site in CI for the first time and have stumbled on to some trouble.

Basically, the site has products like this:
http://www.mysite.com/products/foo
http://www.mysite.com/products/bar

I've created a MY_controller that all the other controllers extend so I am able to make a login system. What I don't understand is how I can make it so that the user can login on every page so when they click on "Login" the same page is loaded but with a form planted on top, e.g:
http://www.mysite.com/products/foo/login

My plan is to use Ajax for this, but as I want the site to degrade gracefully for non-JS-users I'd like to create this approach first. Another alternative would be to have a login-controller that after the login redirects the user to the page where he / she was (pretty much like the one here on the forum), but I'd prefer the first variant.

Any pointers or tips?

Cheers
Stefan
#2

[eluser]SpaceCoder[/eluser]
I recomend you use one path to authorization (for example /login) and store referer in session.
#3

[eluser]Cesar Kohl[/eluser]
I don't understand why you'll make a login with Ajax. Doing it with PHP is much simpler and best practice IMO.

I never had done it but I will someday so let's think together Smile

You'll need to make a code to verify on every page if the user is logged in.

Code:
if(!$this->session->userdata('logged_in')){
    $this->load->view('login')
}else{
    $this->load->view('logged')}
}

You can place it in MY_Controller.

I need to test this but I know the solution is not much different from it.
#4

[eluser]Unknown[/eluser]
[quote author="Cesar Kohl" date="1292185745"]I don't understand why you'll make a login with Ajax. Doing it with PHP is much simpler and best practice IMO.[/quote]

I'll do it with Ajax so the user does not have to reload the entire page and not have to bother with the redirect stuff above. I'll still be using PHP though, albeit together with [removed])
#5

[eluser]Cesar Kohl[/eluser]
Both Facebook and DeviantArt have PHP login.

But now I'm curious about this way you want to achieve. Unfortunately, I can't help you. =/
#6

[eluser]takasia[/eluser]
I don'n know if it would be any help, I have never bouild an AJAX login form, only php - but you can also load and run models from a view file directly, so you could write the do-the-login part in a separate model (you need to load it, but you can do it in the autoload.php), pass to it the URL of the page showing and data from the form, and make it to return tha login result AND the URL opening the same page with the login result as logged in user info or an error...




Theme © iAndrew 2016 - Forum software by © MyBB