Hello I have this simple code:
Client
<?php
function get_url($request_url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
$request_url = 'http://localhost:8080/vb/dashboard/Marketing_dashboard/vb_server.php?function=somefunction';
$response = get_url($request_url);
print_r($response);
Server
if(isset($_GET['function']) && $_GET['function'] == 'somefunction')
{
echo somefunction();
}
function somefunction()
{
return "this is the output of the server";
}
Now I need to add security so that only my client is able to get the data. I thought of a pair keys so I send some hash encripted with the clients private key and the decode it with the public key on the server. But I dont lnow how to implement this. I don't know how to get the keys and I don't know how to do the code.
I'm open to options. How can I make my client the only one able to get the data from that server?
For starters, make the client connect to an https endpoint so it's encrypted. Next, you could pass in a token via an HTTP header and check it on the client side.
The Rackspace APIs use the following header:
Then you can grab the headers, validate the token is correct. If so, execute the function. If not, return a blank page or something else.
You'll set your header like this:
Check it like:
Tested output: