PHP SNIPPET

How to Get Current Page URL using PHP

This php snippet prints current page url. It accepts a Boolean parameter as TRUE/FALSE which acts as a flag for displaying query string. It returns the current site URL.

How to use this function.

PHP SNIPPET

Change Date Format mm/dd/yyyy to yyyy-mm-dd in PHP

One of the common situation I come across often, is to change the date format from mm/dd/yyyy to yyyy-dd-mm. It just take two lines of code to get the results.

You can use an alternative approach also.

PHP SNIPPET

Get IP Address Using PHP

There’s a lot of approach to get ip address in php.  But here’s how I code when I need to get clients Ip address.

Here’s an alternate approach as well,  but I am not sure about this as HTTP_X_FORWARDED_FOR can be anything a client chooses to set, whereas REMOTE_ADDR is considerably harder to fake.

PHP SNIPPET

Get and set timezones in php

If you work with dates and time most of the times, setting up timezones must be your first priority to get accurate results. Using the following snippet you can get and set timezones in php You can find the list of supported timezones from the php official site. To set a timezone use the below snippet.

To […]

PHP SNIPPET

Get current date and time in different formats using php

One of the most commonly used PHP function is date(). Using this snippet you can get current date and time in different formats using PHP. To get current date in different format use the snippet below. For more date formats see php.net and w3schools.

To get current time in different format use the snippet below. For more […]