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 { $jwt ="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwOlwvXC95b3VyZG9tYWluLmNvbSIsImF1ZCI6Imh0dHA6XC9cL3lvdXJkb21haW4uY29tIiwiaWF0IjoxNzMzNDc4MzY4LCJleHAiOjE3MzM0ODE5NjgsImRhdGEiOnsidXNlcklkIjoxMjMsInVzZXJuYW1lIjoiZXhhbXBsZVVzZXIgIn19.srvzJ8zdX5YjTNWfA1MwVB5NfuaJR24Z9GblQzuMjPg"; $secret = 'your_secret_key'; $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