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 base64UrlEncode($data) { return rtrim(strtr(base64_encode($data), '+/', '-_'), '='); } // function base64UrlDecode($data) { // $data .= str_repeat('=', (4 - strlen($data) % 4) % 4); // return base64_decode(strtr($data, '-_', '+/')); // } function jwtEncode($header, $payload, $secret) { // Encode Header $headerEncoded = base64UrlEncode(json_encode($header)); // Encode Payload $payloadEncoded = base64UrlEncode(json_encode($payload)); // Create Signature $signature = hash_hmac('sha256', $headerEncoded . "." . $payloadEncoded, $secret, true); $signatureEncoded = base64UrlEncode($signature); // Create JWT return $headerEncoded . "." . $payloadEncoded . "." . $signatureEncoded; } // Example usage $header = ['alg' => 'HS256', 'typ' => 'JWT']; $payload = [ 'iss' => 'http://yourdomain.com', 'aud' => 'http://yourdomain.com', 'iat' => time(), 'exp' => time() + 3600, // 1 hour expiration 'data' => [ 'userId' => 123, 'username' => 'exampleUser ' ] ]; $secret = 'your_secret_key'; $jwt = jwtEncode($header, $payload, $secret); echo "JWT: " . $jwt; ?>
Show:  
Copy Clear