如何检测php网页是否在Safari之外的iPhone应用程序中运行

时间:2013-05-03 07:59:03

标签: php objective-c xcode

我已经构建了一个iPhone应用程序(不是iPad),我正在Web View控制器中运行一个网页。我的问题是PHP文件如何检测它是从这个App的UIWebView控制器而不是Safari中运行的。如果在这个应用程序中运行,我希望PHP页面的反应不同(即摆脱html菜单),而不是safari移动网络浏览器。这可能吗?

WebView控制器

#import "AccountViewController.h"

@interface AccountViewController ()

@end

@implementation AccountViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidLoad];
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"account" ofType:@"html"]isDirectory:NO];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [_AccountWebView loadRequest:requestObj];
}

-(void)webViewDidFinishLoad:(UIWebView *)webView {
    NSHTTPCookieStorage *sharedHTTPCookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    NSArray *cookies = [sharedHTTPCookieStorage cookiesForURL:[NSURL URLWithString:@"http://www.uniitee.com"]];
    NSEnumerator *enumerator = [cookies objectEnumerator];
    NSHTTPCookie *cookie;
    while (cookie = [enumerator nextObject]) {
        NSLog(@"COOKIE{name: %@, value: %@}", [cookie name], [cookie value]);
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

PHP文件

<?php require_once('Connections/Uniitee.php'); 

$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$palmpre = strpos($_SERVER['HTTP_USER_AGENT'],"webOS");
$berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");

if ($iphone || $android || $palmpre || $ipod || $berry == true) 
{ 
   header('Location: login-m.php');
}

?>

1 个答案:

答案 0 :(得分:1)

您可以在应用中加载其他网址参数,例如?appview=true,并在PHP中加载if($_GET['appview'])

然后,您可以在整个用户会话中设置应用视图为true的会话