How to tell if it’s an AJAX request in PHP

Some of the upcoming jQuery posts I will be publishing will be making AJAX requests so I thought it fitting to post how to tell if the incoming request is an AJAX request in PHP for the PHP programmers out there. This is useful if your script handles both AJAX and non-AJAX requests and you need to know which sort it is.

Categories PHP

Changing the timezone with PHP

Since PHP 5.1.0 it has been possible to change the default timezone that PHP uses using the date.timezone configuration, which can be set for the entire server in php.ini or httpd.conf, on a virtualhost by virtualhost basis, or using the ini_set() function. This post looks at how to change the timezone in PHP using the ini_set function.

Categories PHP

RSS with PHP – Don’t forget to set the Content-Type

Just a quick little post to remind that PHP/Apache sets the content-type header by default to text/html. If you are serving other content, such as an RSS feed, you need to remember to change the content type to the appropriate format.

Categories PHP

Set the content encoding type with PHP headers

Although you can set content type in the HTML <head> section of a web page the web server can also send the content type as one of its headers, and it can cause unexpected consequences when rendering a page in a browser. This post looks at how to set the content encoding type header with PHP.

Categories PHP

Check if a class exists with PHP

PHP has the class_exists() function to check if a class has already been defined. You may need to take action depending if a class exists or not, and need to watch out for "gotchas" when also using __autoload().

Categories PHP