After login how to store session_id and redirect to /page3

How would I store the session_id (user id) then redirect to /page3.
And in page3 controller how would I check if the session is valid, if not redirect to /page1?

Here is the login.php (Server side)

<?php
        //http://stackoverflow.com/questions/18382740/cors-not-working-php
        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);
        }
        //http://stackoverflow.com/questions/15485354/angular-http-post-to-php-and-undefined
        $postdata = file_get_contents("php://input");
        if (isset($postdata)) {
            $request = json_decode($postdata);
            $email = $request->email;
            $password = $request->password;
            $password = md5($password); 
            $conn = new mysqli("127.0.0.1", "***", "***", "***");

            $query="SELECT * FROM users where email = '".$email."' AND password = '".$password."'";         
                $result = $conn->query($query);            
            
                if( $rs=$result->fetch_array(MYSQLI_ASSOC)) {           
                                    
                    $s_id = $rs['id'];

                }   
                $conn->close();     
                echo $s_id;
        }

    ?>

Here is the controller (Client side)

.controller('loginCtrl', ['$scope', '$http', '$stateParams',
	function ($scope, $http, $ionicPopup, $location) {
		$scope.data = {};
	    $scope.submit = function(){
	        var link = 'https://m.socialnetwk.com/home/app/login.php';
	        $http.post(link, {email : $scope.data.email,password : $scope.data.password}).then(function (res){
	            $scope.response = res.data;
	            if ($scope.response !== null) {
	            	$location.path('/page3');
	            }
	            else {
	            	var alertPopup = $ionicPopup.alert({
		                title: 'Login failed!',
		                template: 'Please check your credentials!'
	            	});	
	            } 
	        });
	    };
	}])