eickit
12/5/2017 - 3:38 AM

PHP file to redirect visitors to iOS or Android app files

PHP file to redirect visitors to iOS or Android app files

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>items</key>
	<array>
		<dict>
			<key>assets</key>
			<array>
				<dict>
					<key>kind</key>
					<string>software-package</string>
					<key>url</key>
					<string>http://apps.webniraj.com/my-app/my-app.ipa</string>
				</dict>
				<dict>
					<key>kind</key>
					<string>display-image</string>
					<key>needs-shine</key>
					<true/>
					<key>url</key>
					<string>http://apps.webniraj.com/my-app/iOS-57.png</string>
				</dict>
				<dict>
					<key>kind</key>
					<string>full-size-image</string>
					<key>needs-shine</key>
					<true/>
					<key>url</key>
					<string>http://apps.webniraj.com/my-app/iOS-512.png</string>
				</dict>
			</array>
			<key>metadata</key>
			<dict>
				<key>bundle-identifier</key>
				<string>com.webniraj.my-app</string>
				<key>bundle-version</key>
				<string>1.0</string>
				<key>kind</key>
				<string>software</string>
				<key>subtitle</key>
				<string>WebNiraj</string>
				<key>title</key>
				<string>My App</string>
			</dict>
		</dict>
	</array>
</dict>
</plist>
<?php

if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {

	$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" );
	$webOS = stripos( $_SERVER['HTTP_USER_AGENT'], "webOS" );
	
	// detect os version
	if ( $iPod || $iPhone || $iPad ) {
    // redirect to ipa file download
		header( 'Location: itms-services://?action=download-manifest&url=https://apps.webniraj.com/my-app/my-app.plist' );
		die();
	} else if ( $Android ) {
	  // redirect to apk file download
		header( 'Location: my-app.apk' );
		die();
	}

} else { 
  // add links to each version here for generic Browser support
}