PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE user_value (`user_name` varchar(4), `user_pass` varchar(3)) ;
Copy Clear
Copy Format Clear
<?php function jwtDecode($jwt, $secret) { // Split the JWT into its parts list($headerEncoded, $payloadEncoded, $signatureEncoded) = explode('.', $jwt); // Decode Header and Payload $header = json_decode(base64UrlDecode($headerEncoded), true); $payload = json_decode(base64UrlDecode($payloadEncoded), true); // Verify Signature $signature = base64UrlDecode($signatureEncoded); $expectedSignature = hash_hmac('sha256', $headerEncoded . "." . $payloadEncoded, $secret, true); if ($signature !== $expectedSignature) { throw new Exception('Invalid signature'); } // Check expiration if (isset($payload['exp']) && $payload['exp'] < time()) { throw new Exception('Token has expired'); } return $payload; } // Example usage try { $decodedPayload = jwtDecode($jwt, $secret); echo "User ID: " . $decodedPayload['data']['userId'] . "\n"; echo "Username: " . $decodedPayload['data']['username'] . "\n"; } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ?>
Show:  
Copy Clear