From the pervious post, I was create a tutorial about how to make simple login form with Laravel 4 in here https://imron02.wordpress.com/2013/12/21/simple-login-using-laravel-4/, and now I want add remember me function. So for what remember me function?
Not like form login without remember me, the laravel authentication using the default cookies (name laravel_session) and the cookies have expired time very short (only two hours). Example, if we success login without remember me, so laravel create cookies with time only two hours and if we close the browser and not logout from the page, so if we open the /home page again, we can get in without login again. But if I want open next day, that not work and we must login again.
Okay, now how to implement remember me cookies. Open your simple login from (from the previous post) and open app/views/login.php and change code like this:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <title>Simple Login</title> </head> <body> <?php echo Form::open(array('url' => 'login', 'role' => 'form')) ?> <h2>Please sign in</h2> <!-- if there are login errors, show them here --> <p> <?php if(Session::has('flash_notice')): ?> <div id="flash_notice"><?php echo Session::get('flash_notice') ?></div> <?php endif; ?> </p> <input type="text" name="username" value="<?php echo Input::old('username') ?>" required="required" autofocus="autofocus" autocomplete="off" placeholder="Username" /> <input name="password" placeholder="Password" required="required" type="password" /> <div> <input name="remember" type="checkbox" /> Remember me </div> <input type="submit" value="Sign in" /> <?php echo Form::close() ?> </body> </html>
And if we open the page, we can get result like this:
Then open app/controllers/LoginController.php and change code like this:
<?php class LoginController extends BaseController { public function validate() { // set the remember me cookie if the user check the box $remember = (Input::has('remember')) ? true : false; // attempt to do the login $auth = Auth::attempt( [ 'username' => strtolower(Input::get('username')), 'password' => Input::get('password') ], $remember ); if ($auth) { return Redirect::to('home'); } else { // validation not successful, send back to form return Redirect::to('/') ->withInput(Input::except('password')) ->with('flash_notice', 'Your username/password combination was incorrect.'); } } }
Now open your login page and checklist the remember me input like this:
And this is the different if we using remember me function and not (laravel cookies value):
Look the name remember_*** and look the tab expires. From that, we get result the cookies expires valid until 2019 (Or 5 years from now), and it’s the default cookies expired time from laravel. Form more info see on here http://laravel.com/docs/requests#cookies
The from the result, we get 2 cookies from laravel. For laravel_session is the default cookies from laravel.
So now try to login without checked remember me input, so we can get result only one cookies like this:
Download full source:
laravel_remember.7z
Source:
http://laravel.com/docs/security#authenticating-users
Somebody necessarily lend a hand to make severely posts I might state. That is the first time I frequented your web page and so far? I amazed with the research you made to create this particular post amazing. Magnificent process!
Thanks.. š
Do you have a spam problem on this site; I also am a blogger, and I was wanting to know your situation; many of us have created some nice methods and we are looking to trade methods with other folks, please shoot me an e-mail if interested.
Thanks for your help.. But for now, I only use wordpress plugin to check the spam of any comment. And I also want to know what are the comments coming into my blog, so for today’s comments to be posted, I have to go through approval first. This blog just only my note, and I do not really serious for this blog. I hope with my notes, can also petrified of others out there, and all the info here for free and I was using a free blog. : D
I do accept as true with all the ideas you have introduced on your post. They’re really convincing and will definitely work. Nonetheless, the posts are very brief for novices. May just you please prolong them a little from subsequent time? Thank you for the post.
Hurrah, that’s what I was looking for, what a information! present here at this webpage, thanks admin of this web page.
I am sure this post has touched all the internet viewers, its really really nice article on building up new weblog.
Good post. I learn something totally new and challenging on sites I stumbleupon every day. It’s always interesting to read through content from other authors and use a little something from other web sites.
It’s a pity you don’t have a donate button! I’d definitely donate to this brilliant blog! I suppose for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to new updates and will talk about this website with my Facebook group. Chat soon!
Thanks for your suggestion, I will add donate button later.. š
Hi, i think that i saw you visited my blog so i came to āreturn the favorā.I’m attempting to find things to improve my web site!I suppose its ok to use a few of your ideas!!
Hi there very cool blog!! Guy .. Beautiful .. Wonderful .. I will bookmark your site and take the feeds also? I’m satisfied to search out numerous useful info right here within the put up, we need work out more techniques in this regard, thanks for sharing. . . . . .
Touche. Sound arguments. Keep up the amazing work.
Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You clearly know what youre talking about, why waste your intelligence on just posting videos to your site when you could be giving us something informative to read?
Link exchange is nothing else however it is just placing the other person’s web site link on your page at proper place and other person will also do similar for you.
Does your blog have a contact page? I’m having trouble locating it but, I’d like to shoot you an e-mail. I’ve got some suggestions for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it grow over time.
Sorry for that, I will update to add contact page soon.. š
Hmm it seems like your blog ate my first comment (it was super long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well am an aspiring blog writer but I’m still new to the whole thing. Do you have any helpful hints for novice blog writers? I’d certainly appreciate it.
I do not have any suggestions at all, you need to do is keep writing and see other people’s blogs so that you know how to write a good blog. š
I quite like looking through an article that can make people think. Also, thanks for allowing me to comment!
Hi there to all, the contents present at this web page are genuinely amazing for people knowledge, well, keep up the nice work fellows.
Howdy! I just want to give you a big thumbs up for the excellent info you’ve got right here on this post. I am coming back to your blog for more soon.
This post will assist the internet viewers for setting up new blog or even a blog from start to end.
Truly when someone doesn’t be aware of after that its up to other visitors that they will assist, so here it occurs.
My spouse and I stumbled over here by a different web page and thought I should check things out. I like what I see so now i’m following you. Look forward to looking over your web page for a second time.
If you wish for to take a great deal from this paragraph then you have to apply such techniques to your won webpage.
When someone writes an paragraph he/she keeps the thought of a user in his/her brain that how a user can understand it. Thus that’s why this piece of writing is outstdanding. Thanks!
I’ve been browsing online more than 4 hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. Personally, if all web owners and bloggers made good content as you did, the internet will be a lot more useful than ever before.
For hottest information you have to pay a visit world wide web and on web I found this web site as a best web site for newest updates.
I am actually pleased to read this webpage posts which consists of plenty of helpful information, thanks for providing these kinds of data.
Usually I do not learn post on blogs, however I would like to say that this write-up very forced me to try and do so! Your writing taste has been amazed me. Thank you, quite nice post.
Iām not that much of a online reader to be honest but your sites really nice, keep it up! I’ll go ahead and bookmark your site to come back later on. Cheers
This is a great tip particularly to those fresh to the blogosphere. Short but very accurate informationā¦ Many thanks for sharing this one. A must read post!
Please let me know if you’re looking for a author for your site. You have some really good posts and I believe I would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some content for your blog in exchange for a link back to mine. Please blast me an e-mail if interested. Regards!
My email imron_tux@yahoo.com
This page truly has all of the information and facts I wanted about this subject and didn’t know who to ask.
I like the valuable info you provide in your articles. I’ll bookmark your blog and check again here frequently. I’m quite sure I will learn a lot of new stuff right here! Good luck for the next!
There’s certainly a lot to know about this subject. I really like all the points you have made.
I’m really enjoying the theme/design of your weblog.
Do you ever run into any internet browser compatibility
problems? A number of my blog audience have complained about my
website not working correctly in Explorer but looks great
in Opera. Do you have any advice to help fix this issue?
Thanks on your marvelous posting! I truly enjoyed reading it, you are a great author.I will always bookmark your blog and will often come back someday. I want to encourage continue your great writing, have a nice evening!
My spouse and I stumbled over here from a different page and thought I may as well check things out. I like what I see so now i am following you. Look forward to exploring your web page for a second time.
I just could not leave your website prior to suggesting that I really loved the usual information an individual supply in your visitors? Is going to be again often to check up on new posts
Woah! I’m really enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s challenging to get that “perfect balance” between user friendliness and appearance. I must say you have done a very good job with this. Additionally, the blog loads very fast for me on Firefox. Superb Blog!
I like the valuable information you provide in your articles. I will bookmark your weblog and check again here regularly. I’m quite certain I’ll learn many new stuff right here! Good luck for the next!
For all visitor, If your comment again on this site, I was not confirm because the comment is very long and the page scroll is long too. Thanks for read my blog. š
Thank you for sharing wonderful infos. Your web-site is quite amazing. I am stunned at the details which you have on this internet site. It exposes how beautifully you perceive this unique issue. Bookmarked this web site, will keep returning for added articles. You, my mate, Rock and roll! I ran across only the facts I undoubtedly looked for in all places and just can’t find. Such a wonderful blog.