Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift保存PHP会话以保持身份验证_Php_Ios_Swift - Fatal编程技术网

Swift保存PHP会话以保持身份验证

Swift保存PHP会话以保持身份验证,php,ios,swift,Php,Ios,Swift,我正在构建一个应用程序,它的登录页面使用PHP和MySQL连接到我的AWS服务器,一切正常,只是我不知道如何在应用程序中保存PHP会话,以便用户能够保持身份验证 我的PHP代码的一部分: <?php $session_start(); ... ... if($verify){ echo "Verfied"; $_SESSION["Authenticated"] = 1; } else { echo "Unverified"; $_SESSION["Aut

我正在构建一个应用程序,它的登录页面使用PHP和MySQL连接到我的AWS服务器,一切正常,只是我不知道如何在应用程序中保存PHP会话,以便用户能够保持身份验证

我的PHP代码的一部分:

<?php
$session_start();
...
...
if($verify){
    echo "Verfied";
    $_SESSION["Authenticated"] = 1;
  } else {
    echo "Unverified";
    $_SESSION["Authenticated"] = 0;
  }
...
...
?>

如何在我的应用程序中保存会话,以便用户保持身份验证

为什么不使用JWT令牌?如果您使用的是移动->后端是最好且安全的方式。@UlyssesMarx JWT不是真正安全的:最安全的that php_会话是的,例如,它不是一个标准,第二,这取决于您如何实现您可以构建自己的令牌在PCI Compliance上签名。您的应用程序在您知道如何操作的级别上是安全的。祝你好运
let url = URL(string: "http://localhost/login.php")!
var request = URLRequest(url: url)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
let postString = "username=\(username)&password=\(password)"
request.httpBody = postString.data(using: .utf8)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
    guard let data = data, error == nil else {                                                 // check for fundamental networking error
        print("error=\(String(describing: error))")
        return
    }

    if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {           // check for http errors
        print("statusCode should be 200, but is \(httpStatus.statusCode)")
        print("response = \(String(describing: response))")
    }

    let responseString = String(data: data, encoding: .utf8)!
    print("responseString = \(String(describing: responseString))")
    DispatchQueue.main.async() {
        if (responseString == "Vaild!") {
            self.performSegue(withIdentifier: "MainPageSegue", sender: self)
        } else {
            self.errorLabel.text = "Invalid username or password."
        }
    }
}
task.resume()