繁体   English   中英

登录后重定向到特定 URL

[英]Redirect to specific URL after login

我正在构建一个系统,当有人提出请求时,电子邮件通知将作为接受请求的通知发送给他们的主管。 当主管打开它,然后单击按钮,它重定向到登录页面。 问题是我不知道如何在登录后重定向到特定的批准页面。 电子邮件按钮中的链接是指向特定页面的链接。 当它点击时,它会检查用户是否已经登录。 如果用户已经登录,会顺利跳转到审批页面。 但是当用户没有登录时,它会重定向到登录页面。 用户登录后,如何使其重定向到我在电子邮件中设置的链接。 我已经搜索过了,但我没有得到明确的答案如何解决这个问题。 希望任何人都可以在这里帮助我

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');
            }


        }  
    }

谢谢你 :)

自从您使用 CodeIgniter 以来,您是否看过这个? https://www.formget.com/form-login-codeigniter/

您可以创建一个表单来处理用户登录。

像这样简单的东西(没有任何样式):

<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>

然后你可以设置一个 PHP 脚本来获取表单信息并验证请求

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();
  }
}

然后在yourfile.php ,我们需要确保您是管理员。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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