How to Post Action automatically in php?

59 Views Asked by At

Details are here: First i will hit on this link eg. http://your.app/callback?code=abc123 then i will receive value from code variable from url then i want to redirect this url as a POST action in https://api.another.com/token grant_type=authorization_code& code=[CODE] url, bearing the value of code

1

There are 1 best solutions below

0
On

Use Curl:

An example:

<?php

// if you get the code here from the url,
$code = $_GET['code'];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://api.another.com/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "token_grant_type=authorization_code&code=" + $code);

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

?>