0

How do I secure http call everytime I fire from my app and also it needs to have timeout so that any other user cannot use the same link from any browser.

I am looking for ios solution in particular and not html form.

Please help me out. Unable to resolve this issue and dont know in which direction to proceed.

Thanks in Advance.

I am attaching Working code for both PHP and ios which posts the Request and gets back the Response but no security is attached and any user can get the same Response by calling the same HTTP Response from Browser anytime...

ios code:

    NSURL *url=[NSURL URLWithString:@"http://example.com/getmsgs/strno=123"];

    NSURLRequest *request=[NSURLRequest requestWithURL:url];

    connection=[NSURLConnection connectionWithRequest:request delegate:self];

    if(connection){

        webData=[[NSMutableData alloc]init];

    }


NSError *requestError = NULL;

NSDictionary *allData=[NSJSONSerialization JSONObjectWithData:webdata options:0 error:&requestError];


if (requestError){
    //An error occurred.
    NSLog(@"error is : %@",requestError);
}

if (! allData) {
    NSLog(@"Got an error: %@", requestError);
} else {
    NSLog(@" data is : %@",allData) ;
}



NSArray *arrayOfEntry=[allData objectForKey:@"json"];

for (NSDictionary *diction in arrayOfEntry) {


    NSString *label=[title objectForKey:@"image"];

    NSString *label2=[title objectForKey:@"artist"];

    NSString *label3=[title objectForKey:@"name"];

    [array addObject:label];
        [array addObject:label2];
            [array addObject:label3];

}

php code:

<?php

    $strno=$_GET['strno'];

    if (isset($strno))
    {
            $connect=mysql_connect("localhost","test","test") or die ('Connection error!!!');
            mysql_select_db("test") or die ('Database error!!!');

        $query=mysql_query("select sno FROM users  where strno='$strno';");
        while($row = mysql_fetch_assoc($query))

        {
            $jsonoutput='{"json":{
                "image":"'.$row['image'].'",
"artist":"'.$row['artist'].'",
"name":"'.$row['name'].'"
                }}';
        }

    }

    echo trim($jsonoutput);
    mysql_close($connect) or die ('Unable to close connection-error!!!');
    }

    ?>
4

1 回答 1

0

您可以使用某种会话来实现您想要的。例如,当用户打开(运行)您的 ios 应用程序时,您可以连接到您的网络服务以获取会话密钥(令牌),这对于该应用程序正在运行的设备来说是唯一的。而且,当您的 ios 应用程序进入后台时,您可以使令牌无效(在这里使用 ios 后台执行是合适的)。此外,您可以使用有时间限制的会话密钥,例如,您的会话密钥将在 10 分钟内过期(在服务器端会失效),并且对于新的 Web 请求,您的服务器必须发出另一个会话密钥。祝你好运!

于 2013-04-16T10:22:17.987 回答