mardi 10 octobre 2017

why does this always return false, therefore making it impossible for further checks to be made

I've seen other people with this problem and even found a possible solution, but the solution did not work for me.

var_dump(Token::check(Input::get('token')));

       if(Input::exists()) {       
        if(Token::check(Input::get('token'))) {         
            echo "this has passed";
            $validate = new Validate();
            $validation = $validate->check($_POST, array(
                'first_name' => array(
                    'required' => true,
                    'min' => 1,
                    'max' => 50
                )  
            ));

if($validation->passed()) {
        //register user
        echo 'Passed';
      } else {
          //output error message
          //print_r($validation->errors());
          foreach($validation->errors() as $error) {
            echo $error, '<br>';
          }
      }

    }

here is my check function

public static function check($token) {
        $tokenName = Config::get('session/token_name');
        if(Session::exists($tokenName) && $token === Session::get($tokenName))  {
            Session::delete($tokenName);
            return true;
        }
        return false;
    }

The proposed solution was to add an extra parameter to the check function which would look like this

public static function check($token, $test = false) { 
    $tokenName = Config::get('session/token_name');  
    if(Session::exists($tokenName) && $token === Session::get($tokenName)){ 
        if (!$test) {
            Session::delete($tokenName); 
        }
        return true; 
    } 
    return false; 
}

I tried the proposed solution, but it still comes back as false, which makes it impossible to check if validation has passed. The problem appears to be with the if(Token::check(Input::get('token'))) line which always comes back as false.

Aucun commentaire:

Enregistrer un commentaire