php - Being redirected to login page after being already logged in -


i have login form , i'm logging myself in correct credentials. when logged in did redirect "about" page (used page test functionality). did above following snippet

        $input = input::all();         $login = auth::attempt([             'username' => $input['username'],             'password' => $input['password']         ]);          if($login){             return redirect::to('about');         }         else{             dd('not logged in!');         } 

this snippet working in route page add ->before('auth'); if i'm not logged in i'm going redirected login page , if i'm logged in continue.

code snippet:

route::get('about', function(){     $title = 'about';     return view::make('about')->with('title', $title); })->before('auth'); 

but adding ->before('auth');, i'm being redirected logging page after logging in correct credentials. log in , expect redirect page instead i'm being redirect login page again.

what doing wrong?

edit

did more debugging , i've found out:

redirect route , executing this:

route::get('about', function() {     dd( auth::check() ); // returns false }); 

but instead of redirecting route i'm tried:

if($login){     dd( auth::check() ); // returns true } 

so after redirecting seems i'm getting logged out or that??

you should have auth filter , need check whether logged in/out, :

route::filter('auth', function() {     if (auth::guest()) return redirect::to('login'); }); 

and (filter) code should added in app/filters.php , route (what have)

route::get('about', function(){     $title = 'about';     return view::make('about')->with('title', $title); })->before('auth'); 

also, can use given code below

route::get('about', array('before' => 'auth' ,function() {     $title = 'about';     return view::make('about')->with('title', $title); })); 

update :

also, if using database session make sure primary key id in model (user model) , if not set manually, like

protected $primarykey = "idofthecustomidfieldinthetable"; 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -