CodeIgniter不能使用PHP的命名空间

I'm trying use firebase/php-jwt in CodeIgniter 3, but I get this error:

Parse error: syntax error, unexpected 'use' (T_USE) in /opt/lampp/htdocs/kpittu_api/application/controllers/User.php on line 23

this is my code:

  require('vendor/autoload.php');
  use \Firebase\JWT\JWT;
  $key = "example_key";
  $payload = array(
    "iat" => time(),
    "exp" => time() + 86400,
    "data" => [
      "login" => "sii1995",
      "fname" => "Salim",
      "sname" => "Ibrogimovich",
      "lname" => "Ibrogimov"
    ]
  );
  $jwt = JWT::encode($payload, $key);
  $decoded = JWT::decode($jwt, $key, array('HS256'));
  $decoded_array = (array) $decoded;
  /*
  JWT::$leeway = 60; // $leeway in seconds
  $decoded = JWT::decode($jwt, $key, array('HS256'));
  */

  echo '<pre>';
  print_r($jwt);
  echo '<hr>';
  print_r($decoded_array);
  echo '</pre>';

When I using this code outside CodeIgniter it's work well. How can Use namespace / use keyword in CodeIgniter?

查看全部
douan0729
douan0729
2017/09/19 11:39
  • jwt
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复