Categories
code

Check for AJAX Request in PHP

A simple PHP function to check if the request comes from an AJAX XMLHttpRequest.
Use it if you want your page or script to behave differently when called from AJAX.

The Function:

function isAjax(){
    return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
}

[ad name=”Adsense – text only”]

Categories
code

Detecting Mobile Devices Accessing Your WordPress Site

Mobile web surfing is continuing to evolve on a larger scale. This is why detecting those users who are visiting your WordPress blog through a mobile device and redirecting them to a mobile version of your site is important. In order to achieve this, you first have to get the code from detectmobilebrowsers.mobi and upload it to your theme directory.

[ad name=”Adsense – text only”]

Then, all you simply have to do is open your header.php file and place the following at the top of the file. Remember to edit line 4 to where you’d like to redirect mobile users.

The Source:

include('mobile_device_detect.php');
$mobile = mobile_device_detect();
if ($mobile){
    header('Location: http://your-website.com/?theme=Your_Mobile_Theme');
}