Advertisement
Guest User

Untitled

a guest
Nov 18th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. // securing information and storing variables
  2. $fullname = htmlentities($_REQUEST["fullname"]);
  3. $username = htmlentities($_REQUEST["username"]);
  4. $email = htmlentities($_REQUEST["email"]);
  5. $password = htmlentities($_REQUEST["password"]);
  6. $phone = htmlentities($_REQUEST["phone"]);
  7.  
  8. //if GET or POST are empty
  9. if(empty($fullname) || empty($username) || empty($email) || empty($password) || empty($phone)){
  10.  
  11. $returnArray["status"] = "wrong";
  12. $returnArray["message"] = "some fields are empty";
  13.  
  14. echo json_encode($returnArray);
  15. return;
  16.  
  17. }
  18.  
  19. let config = URLSessionConfiguration.default
  20. let session = URLSession(configuration: config)
  21. let url = URL(string: "http://localhost/php/register.php?")
  22. var request = URLRequest(url: url!)
  23.  
  24. request.httpMethod = "POST"
  25.  
  26. let body = "fullname=(FirstName.text)%20(LastName.text)&username=(UserName.text)&email=(Email.text)&password=(Password.text)&phone=(Phone.text)"
  27.  
  28. request.httpBody = body.data(using: String.Encoding.utf8)
  29.  
  30. let task = session.dataTask(with: url!) {data, response, error in
  31.  
  32. if error != nil {
  33. print(error!.localizedDescription)
  34.  
  35. } else {
  36.  
  37. do {
  38.  
  39. if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any]
  40.  
  41. {
  42.  
  43. print(json)
  44.  
  45. }
  46.  
  47. } catch {
  48. print("error in JSONSerialization")
  49. }
  50.  
  51. }
  52.  
  53. }
  54. task.resume()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement