On Click Button β Redirect to Login Form
Registration form β User enters credentials β Send form
On the corresponding action page, i.e. on the page where you post the data, you will have a username / email address and password
You need to authenticate. Now for authentication, you canβt have direct access to another server database (the cloud database directly), so you need to call the API of the corresponding cloud database database for which you want to authenticate. For this call, you can use a CURL call with POST parameters or any necessary HTTP request, for example GET, POST, PUT, DELETE, PATCH. Make sure you use the TOKEN-based API. Even you can make any secure API calls in accordance with the cloud-based database design for security.
BONUS: So what is a token-based API? Whenever you request an API call for a cross server, i.e. on other servers, make sure you can send some random text along with other parameters. The server, on the other hand, that received your request, do not forget to check this token from the corresponding database table to make sure that you are a valid user and allow you to perform the necessary actions, such as obtaining information about the client, receiving information about the product, etc. ..
The authentication API returns AUTHENTICATED data. Based on this, you can continue to perform actions.
If authentication fails, you can program an error message for invalid credentials for the user.
If its success, you will be granted access, and now you can enter data into your database.
To read data from another database table, since you do not have the required permission, you cannot directly access it. Make an API call to the corresponding function to get all the necessary data, be it GET, POST, PUT, DELETE, PATCH.
Now think that you want to get all the data in the CUSTOMER table, then you will need to make a GET API request that returns JSON data.
Now you have what you want to do with this data. If you want to save this in your database table or play with it on the fly.
To learn how to write an API
For example:
NOTE. I haven't added a security check yet, make sure you work the same
Think that by executing a GET request to get customer information, you can do the following:
API URL: http://127.0.0.1/project/getCustomers.php?token=2fdsd5f42314sfd85sds REQUEST METHOD: GET
getCustomers.php
<?php include_once 'dbConnect.php'; //I am having $link as database link //Only !isset will also work $errors = []; if(empty($_GET['token']) || !isset($_GET['token'])){ $errors[] = 'Token not found!'; }else{ $token = $_GET['token']; } //tokens table will have (id, user_id, token) coloumns $tokenQuery = mysqli_connect($link, "SELECT * FROM tokens WHERE token = '$token' LIMIT 1"); //If I get any result with the respective token if(mysqli_num_rows($tokenQuery) > 0){ $tokenDetails = mysqli_fetch_assoc($tokenQuery); $userId = $tokenDetails['user_id']; /* Now you can check whether the user has Authorization to access the particular module */ $isUserAuthorized = checkUserAuthorizationModule($userId); //Please help your self to do this all checks if($isUserAuthorized === TRUE){ $customersQuery = mysqli_query($link, "SELECT * FROM customers"); $customersDetails = []; if(mysqli_num_rows($customersQuery) > 0){ while($row = mysqli_fetch_assoc($customersQuery)){ $customersDetails[] = $row; } } return json_encode([ 'customerDetails' => $customersDetails ]); } }else{ $errors[] = 'Token is not valid'; } return json_encode([ 'errors' => $errors ]);
Channelsaveer hakari
source share