這幾乎是我在我的應用程序的登錄頁面上工作了將近一天,我想向我的應用程序顯示我的xCode中的錯誤(或任何PHP回聲)應用程序。我會告訴你我的PHP文件和我的Xcode如何從PHP返回Swift UIAlertController
<?php
if($_SERVER['REQUEST_METHOD']=='POST')
{
$password = $_POST['password'];
$email = $_POST['email'];
if($password == '' || $email == '')
{
echo 'Please fill all values.';
}
else
{
require_once('GBconnect.php');
$sql = "SELECT * FROM Users WHERE email='$email' AND password='$password' OR mobile_no='$email' AND password='$password'";
$check = mysqli_fetch_array(mysqli_query($connection,$sql));
if(isset($check))
{
echo 'Login Success';
}
else
{
echo 'Email/Phone or Password is wrong.';
}
mysqli_close($connection);
}
}
else
{
echo 'error';
}
這是我的雨燕文件:
@IBAction func signUp(_ sender: Any)
{
let request = NSMutableURLRequest(url: NSURL(string: "http://34.205.37.201/restapi/GBlogin3.php")! as URL)
request.httpMethod = "POST"
let logEmail = "email=\(username.text!)&& password=\(password.text!)"
let logMobile = "mobile_no=\(username.text!)&& password=\(password.text!)"
if (username.text?.isEmpty)! || (password.text?.isEmpty)!
{
//display message
LoginInfoMyAlertMessage(userMessage: "Please input your Email or Phone and Password.");
}
if let checkNum = Int(username.text!)
{
print(checkNum)
request.httpBody = logMobile.data(using: String.Encoding.utf8)
}
let task = URLSession.shared.dataTask(with: request as URLRequest)
{
data, response, error in
if error != nil
{
print("error=\(String(describing: error))")
}
print("response = \(String(describing: response))")
let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
print("responseString = \(String(describing: responseString))")
}
task.resume()
username.text = ""
password.text = ""
return
你現在看到了什麼結果?你還應該看看https://github.com/Alamofire/Alamofire,這是一個非常好的庫,用於處理Swift – dmorrow
'$ password = $ _POST ['password'];' - >然後我們看不到加密的網絡請求?在PHP方面,你應該不**保存純文本密碼,而是使用PHP內置的'password_hash/password_verify' – OldPadawan