2017-11-03 16:34
浏览 61


there is a change password feature in my admin now before changing password i am validating by asking user to enter the username password again now if the user password is incorrect what i am doing is setting flash data and logging the user out. so when he comes to main login panel he should see the error now here is my code

the controller method

public function checkpassword(){
        $data = $this->input->post();
            echo "true";
            $this->session->set_flashdata('change_password_credentials_error',"Your Username/Password was incorect account was logged out for secutiry reasons!");
            echo "false";

the ajax request

            type: 'post',
            url: '<?php echo base_url()."User/checkpassword/".$this->uri->segment(3).""; ?>',
            data:{ "login_username" : $("#login_username").val(), "login_password" : $("#login_password").val() },
            success: function (data) {
                    window.location.href="<?php echo base_url()."User/changepassword_view/".$this->uri->segment(3)."";?>";
                    window.location.href="<?php echo base_url()."User/logout";?>";


the php script on main login page

        <script>toastr["success"]("<?php echo $this->session->flashdata('change_password_credentials_error')?>");</script>
    <?php } ?>

now the flash data is working just fine i am using it in many other pages but when i am using it with ajax somehow it is not being set! any help?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doulan8846
    doulan8846 2017-11-03 16:47

    What i get about flashdata from codeigniter doc:

    CodeIgniter supports “flashdata”, or session data that will only be available for the next request, and is then automatically cleared.

    From above description, your change_password_credentials_error session will only available at "User/Logout" controller and cleared after controller processed. So, now after then redirected to Login Page the flashdata session will not available.

    For this case, just clear login session after $status variable (else) checking, and then directly move / redirect user to main login page.

    点赞 评论