php识别访问手机操作系统,并直接下载相应的安装包

<?php
header("Content-Type:text/html; charset=utf-8");
if(get_device_type()=='ios'){
	$ff='huanbaoba.ipa';
	header('application/iphone');
	header('Content-Disposition:attachment;filename="huanbaoba.ipa"');
}else{
	$ff='huanbaoba.apk';
	header('application/vnd.android.package-archive');
	header('Content-Disposition:attachment;filename="huanbaoba.apk"');
	
}
readfile($ff); 
function get_device_type(){
	$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
	$type = 'other';
	if(strpos($agent, 'iphone') || strpos($agent, 'ipad')){
		$type = 'ios';
	}
	if(strpos($agent, 'android')){
		$type = 'android';
	}
	return $type;
}

安卓已经测试通过了

ios未测试

你可能感兴趣的:(php识别访问手机操作系统,并直接下载相应的安装包)