Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0Digg thisPin on Pinterest0Email this to someone

Below is a simple PHP script to detect the users device type and then redirect them to the appropriate Apple iTunes App Store or Google Play store – in my case I actually just give the Android User the APK directly:

1. Create PHP file with code on server eg. qr-redirect.php

2. Create QR to link of PHP file eg. http://www.kiteplans.info/qr-redirect.php

When a user then scans the QR they open the PHP code that detects their device and redirects them to the correct Store or File.

<?php

$iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$Android= stripos($_SERVER['HTTP_USER_AGENT'],"Android");

//check if user is using ipod, iphone or ipad...
if( $iPod || $iPhone || $iPad ){
        //we send these people to Apple Store
        header('Location: http://itunes.apple.com/YOUAPPLINK'); // <-apple store link here
}else if($Android){
        //we send these people to Android Store
        //header('Location: https://play.google.com/store/apps/YOUAPPLINK'); // <-android store link here
		// or we can give them the APK Directly

		$file = '/yourlocation/yourapp.apk'; //not public folder

        $fileSize = filesize($file);

         if (file_exists($file)) {
             header('Content-Description: File Transfer');
             header('Content-Type: application/vnd.android.package-archive');
             header('Content-Disposition: attachment; filename='.basename($file));
             header('Content-Transfer-Encoding: binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Pragma: public');
             header('Content-Length: ' . $fileSize);
             ob_clean();
             flush();
             readfile($file);
             exit;
         }

}else{
		//we send all undetected to site
        header('Location: http://kiteplans.info/'); // <-site link here
}

?>
If you enjoyed this post, why not leave a comment or consider a Donation as a token of your appreciation. If you need help implementing something you saw on this site or any other project why not Hire Me?
How to: QR Code – Multi Platform – Apple App Store and Android Google Play Store – redirect PHP
Tagged on:                                                                     

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading Facebook Comments ...