Postingan

Menampilkan postingan dari Agustus, 2023

How to download an image from a URL using file_get_contents in PHP, resize the image using the GD library, and then encode the resized image as BASE64.

Here's an example of how to download an image from a URL using file_get_contents in PHP, resize the image using the GD library, and then encode the resized image as BASE64.php // URL of the image you want to download and resize $imageUrl = 'https://example.com/path/to/your/image.jpg'; // Download the image using file_get_contents $imageData = file_get_contents($imageUrl); if ($imageData === false) { echo 'Failed to download the image.'; exit; } // Create an image resource from the downloaded image data $originalImage = imagecreatefromstring($imageData); if ($originalImage === false) { echo 'Failed to create image resource.'; exit; } // Get the original image dimensions $originalWidth = imagesx($originalImage); $originalHeight = imagesy($originalImage); // Calculate the new dimensions for the resized image $newWidth = 200; // Replace with the desired width for the resized image $newHeight = ($originalHeight / $originalWidth) * $newWi...

Create token using JSON Web Tokens (JWT)

To create a web token using JSON Web Tokens (JWT) in a web application, you can use libraries available in your programming language. Here, I'll demonstrate how to create a JWT in PHP using the "firebase/php-jwt" library. 1. Install the "firebase/php-jwt" library: Use Composer to install the PHP-JWT library. If you don't have Composer installed, you can download it from https://getcomposer.org/. Run the following command in your project's root directory to install the library: composer require firebase/php-jwt 2. Create a PHP script to generate a JWT: Create a new PHP file (e.g., generate_jwt.php) and add the following code: require __DIR__ . '/vendor/autoload.php'; // Include the composer autoloader use \Firebase\JWT\JWT; use \Firebase\JWT\Key; // Replace these values with your own secret key and any other claims you want to include in the token $secretKey = 'your_secret_key'; $issuedAt = time(); $expirationTime = $issued...

Add these security headers to your website

The X-Frame-Options, Strict-Transport-Security, X-Content-Type-Options, Referrer-Policy, Permissions-Policy, and Content-Security-Policy headers are security-related HTTP headers that help enhance the security of web applications. To add these security headers to your website, you can use the .htaccess file for Apache web servers or the server configuration for other web servers. Here's how to set each header: 1. X-Frame-Options: The X-Frame-Options header helps prevent clickjacking attacks by controlling whether your website can be embedded in an iframe on another domain. For Apache (using .htaccess): Header always set X-Frame-Options "SAMEORIGIN" 1. Strict-Transport-Security (HSTS): The Strict-Transport-Security header enforces the use of HTTPS by instructing the browser to only access the website over a secure (HTTPS) connection. For Apache (using .htaccess): Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains" ...