Part of the EllisLab Network
   
 
login on every page
Posted: 26 August 2006 11:02 AM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  79
Joined  08-26-2006

hi everyone

i am just starting out with CI - i really want to use it for a website i am starting - however - i cant seem to get my head around how to have a login form on every page.

at the moment i have the login form as part of my header.php in the “views” folder. but that is as far as I can get.

i want to just use my own login code (which simply checks the db and sets the sessions - or returns an error message) but i have no idea how to set this all up in the mvc approach. i also dont know how to redirect the user back to the same page they were viewing before submitting the login form (i would normally use hidden or get fields here if I wasnt using CI).

basically - i am lost. any help would be appreciated - if i can get past this i know CI will be very beneficial.

cheers.

Profile
 
 
Posted: 26 August 2006 11:06 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  424
Joined  04-03-2006
woopsicle - 26 August 2006 11:02 AM

hi everyone

i am just starting out with CI - i really want to use it for a website i am starting - however - i cant seem to get my head around how to have a login form on every page.

Check out my new mini-app download…. it has the code example as a little app that does nothing but user authorization.

 Signature 

George Dunlop - This-Page.com

Profile
 
 
Posted: 26 August 2006 11:10 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  79
Joined  08-26-2006
Peccavio - 26 August 2006 11:06 AM
woopsicle - 26 August 2006 11:02 AM

hi everyone

i am just starting out with CI - i really want to use it for a website i am starting - however - i cant seem to get my head around how to have a login form on every page.

Check out my new mini-app download…. it has the code example as a little app that does nothing but user authorization.

thanks for the reply - the download link isnt working for me though?

Profile
 
 
Posted: 26 August 2006 11:21 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  424
Joined  04-03-2006
woopsicle - 26 August 2006 11:10 AM

thanks for the reply - the download link isnt working for me though?

Try the link again… your post was while I was setting up the post right b4 yours. My link was initially broken… but fixed… You will find good code example for your question

 Signature 

George Dunlop - This-Page.com

Profile
 
 
Posted: 26 August 2006 10:31 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  351
Joined  07-25-2006

Create a view that is included on every page.
Create a form with a hidden value of ‘$this->uri->uri_string()’. Have the form action as as ‘/login/’.
Create a Login controller that does the login. Have the Login controller ‘redirect($this->input->post(“hidden_url”)’.

Done. Obviously, you’d want error checking, etc, but that’s the basic concept.

 Signature 

me and some random code, hosted by dh. and a blog too! ++ dead bugs

Profile
 
 
Posted: 27 August 2006 10:13 PM   [ Ignore ]   [ # 5 ]  
Grad Student
Avatar
Rank
Total Posts:  79
Joined  08-26-2006

thanks shadowhand - that really helped.. i have now mostly got it all working.

one problem i had was that $this->uri->uri_string() wasn’t outputting anything for the hidden field (i tried echo’ing it too). I have definitely got the uri library in the autoload.php file.
i have just used PHP_SELF instead for now and it all works.

Profile
 
 
Posted: 30 August 2006 06:01 AM   [ Ignore ]   [ # 6 ]  
Summer Student
Total Posts:  20
Joined  07-19-2006

instead of $this->uri->uri_string() in a hidden filed you can also use native-session and their flasvars feature.

Did you figure out how to use login form on every page, when your using the ci validation class. Since validation code is usually in the controller.

if ($this->validation->run() == FALSE)
        
{//validation failed            
            
$this->load->view('misc/loginform',$data);
        
}
        
else
        
{    // validation passed try

                        //do some loginstuff
                 
redirect('goBackToPage');
        
}

The mini-app doesn’t use ci validation on the loginform…

Profile
 
 
Posted: 30 August 2006 07:35 PM   [ Ignore ]   [ # 7 ]  
Grad Student
Rank
Total Posts:  51
Joined  07-17-2006

You might also look into the FILTER system on the wiki page.

http://www.codeigniter.com/wiki/Filters_system/

I’ve incorporated it in my application and it took 5 minutes only.

I’ve edited the file: system/application/filters/auth.php to suit my needs.

cheers
shaffick

Profile
 
 
Posted: 30 August 2006 08:30 PM   [ Ignore ]   [ # 8 ]  
Grad Student
Avatar
Rank
Total Posts:  79
Joined  08-26-2006

Ananda - I didnt use the validation functions for the login part - but i have used it on the registration page and i think it is fantastic and so easy to use!
Shaffick - i will look into the filters system thanks.

I have the login system working well now. thanks for everyones help.
I am really starting to love CI - I like how i can use as little or as much of the MVC approach as I like.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120496 Total Logged-in Users: 27
Total Topics: 126565 Total Anonymous Users: 4
Total Replies: 665437 Total Guests: 343
Total Posts: 792002    
Members ( View Memberlist )