简体   繁体   中英

Redirect to specific URL after login

I am building a system when someone requesting, the email notification is sent to their supervisor as a notification to accept the request. When the supervisor open it, then click to the button, it redirect to the login page. The problem is I don't know how to redirect to spesific approval page after login. The link in email button is link to spesific page. When it click, it check if the user already login or not. If user already login, it will smoothly ridirect to approval page. But when the user hasn't login it will redirect to login page. After the user login, how to make it redirect to the link I set in email. I've search in but I didn't get clear answer how to solve this. Hope anyone can help me here

function do(){

    $nik = $this->input->post('nik');       
    $pwd = sha1($this->input->post('pwd') . $this->config->item('encryption_key'));
    $login = $this->Login_model->auth($nik, $pwd);

    $rules = array(
        array(
            'field' => 'nik',
            'label' => 'NIK',
            'rules' => 'required'
        ),
        array(
            'field' => 'pwd',
            'label' => 'Password',
            'rules' => 'required'
        )
    );
    $this->form_validation->set_rules($rules);

        if ($this->form_validation->run() == FALSE) {
            $this->session->set_flashdata('error', 'Error message.');
            $this->load->view('v_login');
        } else {
            if ($login == NULL) {
                echo "<script>alert('Check your NIK or Password or Register new account')</script>";
                redirect('login','refresh');
            }else {
                $data = array(
                    'ID'        => $login->no,
                    'nik'       => $login->nik,
                    'name'      => $login->name,
                    'email'     => $login->email,
                    'is_login'  => TRUE
                );

                $this->session->set_userdata($data);
                $session_nik = $login->nik;
                redirect('dashboard');
            }


        }  
    }

Thank You :)

Since you are using CodeIgniter have you looked at this? https://www.formget.com/form-login-codeigniter/

You can create a form that will handle logging in the user.

Something simple like this (without any styling):

<form action="" method="post" name="login_form">
  <input type="text" name="username">
  <input type="text" name="password">
  <input type="submit" name="submit" value="Login">
</form>

Then you can setup a PHP script to get the form information and validate the request

if(isset($_POST['submit'])) {
  if($_POST['username'] == 'example' && $_POST['password'] == 'password') {
    // Let them through
    $_SESSION["admin"] = true;
    ob_start();
    header('Location: yourfile.php');
    ob_end_flush();
  } else {
    // You would set this up yourself.
    die();
  }
}

Then on the yourfile.php , we need to make sure you are an admin.

if ($_SESSION["admin"] == false) {
  ob_start();
  header('Location: login.php');
  ob_end_flush();
  die();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM