Session API request (PHP)
See original GitHub issueDears,
We are getting this below error while connecting to your api, please check anything missing
Error: {“errors”:[“Unexpected signature”]}
Php Code:
function callAPI($method, $url, $data){
$curl = curl_init();
switch ($method){
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
// OPTIONS:
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Length: ' . strlen($data),
'Content-Type: application/json',
//'CB-Token : '. rand(1000,10000)
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// EXECUTE:
$result = curl_exec($curl);
print_r($result);
if(!$result){die("Connection Failure");}
curl_close($curl);
return $result;
}
$_SESSION["nonce"] = rand(1000,10000);
$has = 'application_id=xxxxx&auth_key=xxxx&nonce="'.$_SESSION["nonce"].'"×tamp='.time().'';
$has = hash_hmac('sha1',$has,'xxxxx');
//echo strtotime(date('Y-m-d H:i:s')).'<br>';
//echo $_SESSION["nonce"] .'<br>';
//echo $has.'<br>';//exit;
$data = '{"application_id": "xxx", "auth_key": "xxx", "nonce": "'.$_SESSION["nonce"].'", "timestamp": "'.time().'", "signature": "'.$has.'"}';
//echo $data;
//echo date('');
callAPI("POST",'https://api.connectycube.com/session',$data);
unset($_SESSION["nonce"]);
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
How to make use of session in REST API - Stack Overflow
1 Answer 1 · It retrieve the session_id from the request · It tries to retrieve the account associated to the session_id from...
Read more >10.5 PHP Session API and Configuration - eTutorials.org
Creates a new session, or finds an existing one. Checks for a session ID in the HTTP request?either as a cookie or a...
Read more >Goodbye PHP Sessions, Hello JSON Web Tokens - Coderwall
REST API's are meant to be stateless. What that means is that each request from a client should include all the information needed...
Read more >Session on API request - Laracasts
I want to use session on api request. I have changed config/auth.php file like below 'guards' => [ 'web' => [ 'driver' =>...
Read more >Where do you recommend to store session keys for my REST ...
I'm currently developing my first REST API (tough I have written other non-rest ... You can use the built in PHP session, you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here is a complete create session request, could you please try it and let us know:
In a case somebody needs to create a session with user: