Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here is my login php code
- <?php
- ob_start();
- session_start();
- $errmsg_arr = array();
- $errflag = false;
- if (isset($_SERVER['HTTP_ORIGIN'])) {
- header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
- header('Access-Control-Allow-Credentials: true');
- header('Access-Control-Max-Age: 86400'); // cache for 1 day
- }
- // Access-Control headers are received during OPTIONS requests
- if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
- if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
- header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
- if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
- header("Access-Control-Allow-Headers:{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
- exit(0);
- }
- $errors = array();
- $data = array();
- // Getting posted data and decodeing json
- $_POST = json_decode(file_get_contents('php://input'), true);
- require_once 'db_functions.php';
- $db = new db_functions();
- if(empty($_POST['doc_key']))
- {
- $data['errors'] = 'Please enter all the credentials';
- echo json_encode($data);
- }
- else if(empty($_POST['password']))
- {
- $data['errors'] = 'Please enter all the credentials';
- echo json_encode($data);
- }
- else
- {
- $doc_key = $_POST['doc_key'];
- $password = $_POST['password'];
- $user = $db->getDoctorByEmailAndPassword($doc_key, $password);
- if( $user == true)
- {
- //session_regenerate_id();
- $_SESSION['name'] = $user["name"];
- $_SESSION['contact'] = $user["contact"];
- $_SESSION['email'] = $user["email"];
- $_SESSION['license_no'] = $user["license_no"];
- $_SESSION['type'] = $user["type"];
- $_SESSION['gender'] = $user["gender"];
- $_SESSION['location'] = $user["location"];
- $_SESSION['fees'] = $user["fees"];
- $_SESSION['experience'] = $user["experience"];
- $_SESSION['doc_key'] = $user["doc_key"];
- //session_write_close();
- $data['message'] = $_SESSION['name'];// "User logged in successfully";
- echo json_encode($data);
- }
- else
- {
- $data['errors'] = 'Login Credentials are invalid';
- echo json_encode($data);
- }
- }
- ?>
- <?php
- ob_start();
- session_start();
- if (isset($_SERVER['HTTP_ORIGIN'])) {
- header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
- header('Access-Control-Allow-Credentials: true');
- header('Access-Control-Max-Age: 86400'); // cache for 1 day
- }
- // Access-Control headers are received during OPTIONS requests
- if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
- if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
- header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
- if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
- header("Access-Control-Allow-Headers:{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
- exit(0);
- }
- $data = array();
- $type_user = "";
- if(isset($_SESSION['user_name']) || isset($_SESSION['license_no']))
- {
- if($type_user == "doctor")
- {
- $data["name"] = $_SESSION["name"];
- $data["email"] = $_SESSION["email"];
- $data["contact"] = $_SESSION["contact"];
- $data["license_no"] = $_SESSION["license_no"];
- $data["doc_key"] = $_SESSION["doc_key"];
- $data["gender"] = $_SESSION["gender"];
- $data["type"] = $_SESSION["type"];
- $data["location"] = $_SESSION["location"];
- $data["fees"] = $_SESSION["fees"];
- $data["experience"] = $_SESSION["experience"];
- echo json_encode($data);
- }
- else
- {
- $data["name"] = $_SESSION["name"];
- $data["email"] = $_SESSION["email"];
- $data["contact"] = $_SESSION["contact"];
- $data["gender"] = $_SESSION["gender"];
- $data["user_name"] = $_SESSION["user_name"];
- echo json_encode($data);
- }
- }
- else
- {
- $data["errors"] = "Please login first to see this";
- echo json_encode($data);
- }
- ?>
- .controller('doctorloginCtrl', function($scope,$http,$window) {
- $scope.doctor = {};
- $scope.loginDoc = function(){
- $http({
- method: 'POST',
- url: 'http://localhost/drmedic/login_doctor.php',
- data: $scope.doctor,
- headers: {'ContentType': 'application/x-www-form-urlencoded'}
- })
- .success(function(data){
- if(data.errors)
- {
- alert(JSON.stringify(data.errors));
- }
- else
- {
- alert(JSON.stringify(data.message));
- $window.location.href = "#/home";
- }
- });
- }
- })
- .controller('profileCtrl', function($scope,$http,$ionicSideMenuDelegate,$window) {
- $ionicSideMenuDelegate.toggleLeft();
- $http({method: 'GET', url: 'http://localhost/drmedic/retrieve_login_details.php'}).success(function(data) {
- if(data.errors)
- {
- alert(data.errors);
- $window.location.href = "#/select-role";
- }
- else
- {
- $scope.contents = data;
- console.log($scope.contents);
- }
- });
- })
- <ion-view title="Profile">
- <ion-content overflow-scroll="true" padding="true" scroll="false" class="has-header">
- Hi {{contents.name}}
- </ion-content>
- </ion-view>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement