Advertisement
Guest User

Untitled

a guest
Mar 11th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. Here is my login php code
  2.  
  3. <?php
  4. ob_start();
  5. session_start();
  6. $errmsg_arr = array();
  7. $errflag = false;
  8.  
  9. if (isset($_SERVER['HTTP_ORIGIN'])) {
  10. header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
  11. header('Access-Control-Allow-Credentials: true');
  12. header('Access-Control-Max-Age: 86400'); // cache for 1 day
  13. }
  14.  
  15. // Access-Control headers are received during OPTIONS requests
  16. if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
  17.  
  18. if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
  19. header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
  20.  
  21. if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
  22. header("Access-Control-Allow-Headers:{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
  23.  
  24. exit(0);
  25. }
  26.  
  27. $errors = array();
  28. $data = array();
  29.  
  30. // Getting posted data and decodeing json
  31. $_POST = json_decode(file_get_contents('php://input'), true);
  32.  
  33. require_once 'db_functions.php';
  34. $db = new db_functions();
  35.  
  36.  
  37. if(empty($_POST['doc_key']))
  38. {
  39. $data['errors'] = 'Please enter all the credentials';
  40. echo json_encode($data);
  41. }
  42. else if(empty($_POST['password']))
  43. {
  44. $data['errors'] = 'Please enter all the credentials';
  45. echo json_encode($data);
  46. }
  47. else
  48. {
  49. $doc_key = $_POST['doc_key'];
  50. $password = $_POST['password'];
  51. $user = $db->getDoctorByEmailAndPassword($doc_key, $password);
  52. if( $user == true)
  53. {
  54. //session_regenerate_id();
  55. $_SESSION['name'] = $user["name"];
  56. $_SESSION['contact'] = $user["contact"];
  57. $_SESSION['email'] = $user["email"];
  58. $_SESSION['license_no'] = $user["license_no"];
  59. $_SESSION['type'] = $user["type"];
  60. $_SESSION['gender'] = $user["gender"];
  61. $_SESSION['location'] = $user["location"];
  62. $_SESSION['fees'] = $user["fees"];
  63. $_SESSION['experience'] = $user["experience"];
  64. $_SESSION['doc_key'] = $user["doc_key"];
  65. //session_write_close();
  66. $data['message'] = $_SESSION['name'];// "User logged in successfully";
  67. echo json_encode($data);
  68. }
  69.  
  70. else
  71. {
  72. $data['errors'] = 'Login Credentials are invalid';
  73. echo json_encode($data);
  74. }
  75. }
  76. ?>
  77.  
  78. <?php
  79. ob_start();
  80. session_start();
  81. if (isset($_SERVER['HTTP_ORIGIN'])) {
  82. header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
  83. header('Access-Control-Allow-Credentials: true');
  84. header('Access-Control-Max-Age: 86400'); // cache for 1 day
  85. }
  86.  
  87. // Access-Control headers are received during OPTIONS requests
  88. if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
  89.  
  90. if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
  91. header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
  92.  
  93. if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
  94. header("Access-Control-Allow-Headers:{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
  95.  
  96. exit(0);
  97. }
  98. $data = array();
  99. $type_user = "";
  100. if(isset($_SESSION['user_name']) || isset($_SESSION['license_no']))
  101. {
  102. if($type_user == "doctor")
  103. {
  104. $data["name"] = $_SESSION["name"];
  105. $data["email"] = $_SESSION["email"];
  106. $data["contact"] = $_SESSION["contact"];
  107. $data["license_no"] = $_SESSION["license_no"];
  108. $data["doc_key"] = $_SESSION["doc_key"];
  109. $data["gender"] = $_SESSION["gender"];
  110. $data["type"] = $_SESSION["type"];
  111. $data["location"] = $_SESSION["location"];
  112. $data["fees"] = $_SESSION["fees"];
  113. $data["experience"] = $_SESSION["experience"];
  114. echo json_encode($data);
  115. }
  116. else
  117. {
  118. $data["name"] = $_SESSION["name"];
  119. $data["email"] = $_SESSION["email"];
  120. $data["contact"] = $_SESSION["contact"];
  121. $data["gender"] = $_SESSION["gender"];
  122. $data["user_name"] = $_SESSION["user_name"];
  123. echo json_encode($data);
  124. }
  125.  
  126. }
  127. else
  128. {
  129. $data["errors"] = "Please login first to see this";
  130. echo json_encode($data);
  131. }
  132. ?>
  133.  
  134. .controller('doctorloginCtrl', function($scope,$http,$window) {
  135. $scope.doctor = {};
  136. $scope.loginDoc = function(){
  137. $http({
  138. method: 'POST',
  139. url: 'http://localhost/drmedic/login_doctor.php',
  140. data: $scope.doctor,
  141. headers: {'ContentType': 'application/x-www-form-urlencoded'}
  142. })
  143. .success(function(data){
  144. if(data.errors)
  145. {
  146. alert(JSON.stringify(data.errors));
  147. }
  148. else
  149. {
  150. alert(JSON.stringify(data.message));
  151. $window.location.href = "#/home";
  152. }
  153. });
  154. }
  155. })
  156.  
  157. .controller('profileCtrl', function($scope,$http,$ionicSideMenuDelegate,$window) {
  158. $ionicSideMenuDelegate.toggleLeft();
  159. $http({method: 'GET', url: 'http://localhost/drmedic/retrieve_login_details.php'}).success(function(data) {
  160. if(data.errors)
  161. {
  162. alert(data.errors);
  163. $window.location.href = "#/select-role";
  164. }
  165. else
  166. {
  167. $scope.contents = data;
  168. console.log($scope.contents);
  169. }
  170. });
  171.  
  172. })
  173.  
  174. <ion-view title="Profile">
  175. <ion-content overflow-scroll="true" padding="true" scroll="false" class="has-header">
  176. Hi {{contents.name}}
  177. </ion-content>
  178. </ion-view>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement