Category Archives: PHP

Parse URL in PHP using `parse_url` and add/modify query parameters

The parse_url function in PHP is used to parse a URL into its components such as scheme, host, path, query, and more. However, it doesn’t have a direct feature for modifying or adding parameters to a URL. To achieve that, you need to manually manipulate the parsed components and then reassemble the URL. Here’s how … Continue reading Parse URL in PHP using `parse_url` and add/modify query parameters

Preventing form re-submission on reload

Preventing form submission when a user reloads a page can be useful to avoid unintended data resubmission. You can achieve this using the Post/Redirect/Get (PRG) pattern along with JavaScript. Here’s how you can do it: Server-side Handling (Post/Redirect/Get Pattern): When the form is submitted, process the data on the server, perform the necessary actions, and … Continue reading Preventing form re-submission on reload

How to Convert Date and Time from One Time Zone to Another

Using PHP It’s really simple to convert a DateTime from one time zone to another in PHP. Just create a DateTime object using date & time to be converted as the first parameter and the original time zone as the second parameter. Then change the time zone to the desired one using the setTimezone method. That’s all! $date = new DateTime(‘2022-02-01 … Continue reading How to Convert Date and Time from One Time Zone to Another