Created
November 4, 2020 11:02
-
-
Save foxfabi/eca3fa71c4b714e0958fdbc476778460 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = "https://randomname.de/"; | |
$params = array( | |
"count" => "1", // gewünschte Anzahl der Resultate | |
"gender" => "b", // männliche und weibliche User generieren | |
"minAge" => "18", // minimale Alter der Nutzer | |
"format" => "json" // Typ des Ausgabeformat | |
); | |
// Abhängig von der API, hier json | |
$headers = array( | |
'Accept: application/json', | |
'Content-Type: application/json', | |
); | |
$url .= '?' . http_build_query($params); | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $url); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
$response = curl_exec($curl); | |
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE); | |
curl_close($curl); | |
if ($code == 200) { | |
$response = json_decode($response, true); | |
print_r($response); | |
} else { | |
echo 'error ' . $code; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment