简体   繁体   中英

PHP: Post variable is set. Undefined index

Having this fragment of php code:

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    print_r($_POST);
    if( isset( $_POST['user_token'] ) )
    {
        echo 'ok';
    }
    if( user_token_validity( $_POST['user_token'] ) )
    {

The request method is correct. In the POST array, the user_token variable is correctly set as POST variable through Postman.

When I call the function user_token_validity , this happens:

Array
(
    [------WebKitFormBoundarydDwxPLxbqyT4BzAo
    Content-Disposition:_form-data;_name] => "user_token"

    b66df4ca4547679d062e2595953b608b5b38ce42af095abb92b65624e801af35
    ------WebKitFormBoundarydDwxPLxbqyT4BzAo--

)


Notice: Undefined index: user_token in
/public_html/api/getProfileImage.php on line 12  

As you can see, the variable user_token is correctly passed and enhanced too: this is the output from Postman setting as input parameters the token and method POST.

Line 12, is where the function is called.

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
print_r($_POST);
if (isset($_POST['user_token'])){
  echo 'ok';
if (user_token_validity(array_column($_POST,'user_token')){
   }
  }
}

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