doufu6130 2017-02-02 14:37
浏览 44

当我已登录时,我想阻止返回登录页面

how can i supposed to do that? i think i miss some queries . I hope you guys can help me with this. How to prevent user from going back to the login-page after successful login using back button . Because when I login in and pressed back im going back to my login page. Need help everyone. im using laravel framework

 public function login(Request $req)
 {
     $username=$req->input('email');
     $password=$req->input('password');
     $breadcrumb = 'Dashboard';
     $pageTitle = 'CollabUX | Dashboard';
     $prepath ='../';
     $currentURL = Req::url();

     $user = DB::table('add_users')->where(['username'=>$username,'password'=>$password])->get();    

     if(count($user)>0){
     // Store a piece of data in the session...
     session(['isloggedin' => 'true']);
     return View::make('dashboard')->with(
     array('breadcrumb' => $breadcrumb,'pageTitle' => $pageTitle,'currentURL' => $currentURL,'prepath' => $prepath));
 }
 else{
     //imbes na empty page, redirect ka ulit sa login page
     $data = array(
                   'error'  => 1,
                   'remarks' => 'Invalid Username/Password. Please try again.'
                    );
                    return View::make('login')->with('data', $data);
                }      
            }
  • 写回答

2条回答 默认 最新

  • douzhuo1853 2017-02-02 14:44
    关注

    You can do this by using session_start() On the start of your home page add this line

    session_start() now on you login page do the following

    if(isset($_SESSION['user'])){
         // redirect user to $_SERVER['HTTP_REFERER']
     }
    

    and in your login function after successful login do this

    $_SESSION['user'] = //<user name of logged in user>
    

    on logout do this

    session_destroy()
    

    $_SESSION array can hold any number of user defined values, you can use this to store all the data related to a session

    $_SERVER['HTTP_REFERER'] will take user to the last url, you might want to change it according to your requirements

    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序