1
<?
$password = substr(md5(microtime()) , rand(0, 26) , 8);
$username = 'SAG' . $password;
$params = ['username' => $username, 'mobile' => 'yes', 'lang' => 'en', 'game_code' => 'lobby', 'page_site' => 'live'];
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://api.gmaster8.com/BBIN/game/open",
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => $params,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => array(
        "Authorization: Basic U0FHQVBJOjEyMzRxd2Vy"
    ) ,
    CURLOPT_USERPWD => "$username:$password",
));
$result = curl_exec($curl);
echo $result;
?>

I got the $result like this:

{"url":"https:\/\/888.gsoftbb.com\/app\/WebService\/JSON\/display.php\/Login?website=gamingsoft&uppername=dgmaster8rmb&username=C71SAGabfbbcc9&lang=en-us&page_site=live&page_present=live&key=t7ksrtefa9e54610003dfb2b05986de7fcfa6btsmtpho&"}

How can I post the API and then load the url in response from API server? What code should I replace the line

echo $result;

to load the url in json response from API server?

2 Answers 2

1

Try this where you have echo $result

$result = json_decode($result, true);
header("Location: {$result['url']}");
Sign up to request clarification or add additional context in comments.

Comments

0

You can do it this way:

[...]
$ json = json_decode ($ result);
print_r ($ json);

Or that way if you want to print in a more friendly way:

[...]
$ result = curl_exec ($ curl);
header ("Content-type: application / json");
$ json = json_decode ($ result, JSON_PRETTY_PRINT);
print_r ($ json);

json_decode transforms your string into JSON and json_encode transforms your JSON into a string.

json_decode accepts flags, such as JSON_PRETTY_PRINT. See more at https://www.php.net/manual/pt_BR/function.json-encode.php

EDIT

That said, if you want to redirect to the URL returned in JSON, instead of printing the returned value, just do the following:

[...]
$ result = curl_exec ($curl);
$ json = json_decode ($result);
header("Location: {$result['url']}");

Hope this helps.

3 Comments

I follow your code but it still only print the result in array with beatiful format: but the page not forward or reload to open URL in json.
I follow your code but it still only print the result in array with beatiful format Array ( [url] => https://888.gsoftbb.com/app/WebService/JSON/display.php/Login?website=gamingsoft&uppername=dgmaster8rmb&username=C71SAGbc8b93ff&lang=en-us&page_site=live&page_present=live&key=ieiviz7c6ba0db174d9d828db5bbec2c23acc0aglzbdb& ) but not open that URL.
I have try with replace function and I can handle it now <? ........ $result = str_replace('\/','/',curl_exec($curl)); $result = str_replace('{"url":"','',$result); $result = str_replace('"}','',$result); ?> <a href="<? echo $result; ?>" target="_blank">OPEN URL</a>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.