Problem with API call

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
joms
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Dec 11, 2019 11:43 pm

Wed Dec 11, 2019 11:54 pm

Hello all,

Im pretty new to PHP but im trying to setup a page that gets information from an API but all im getting is a blank page and no errors so i think im missing some code, but i cannot for the life of me see where.

PHP 7.3.9 (cgi-fcgi) (built: Aug 28 2019 09:28:24)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies
Running on IIS.

Hope i can get a helping hand here since my mind is starting to hurt:)

Code: Select all

<?php
$curl1 = curl_init();
$curl2 = curl_init();


curl_setopt_array($curl1, array(
                             CURLOPT_URL => "URL-1",
                             CURLOPT_CUSTOMREQUEST => "GET",
                             CURLOPT_RETURNTRANSFER => true,
                             CURLOPT_HTTPHEADER => array(
                                                          "authorization: Basic API-KEY"
                             ),
));


curl_setopt_array($curl2, array(
                             CURLOPT_URL => "URL-2",
                             CURLOPT_CUSTOMREQUEST => "GET",
                             CURLOPT_RETURNTRANSFER => true,
                             CURLOPT_HTTPHEADER => array(
                                                          "authorization: Basic API-KEY"
                             ),
));


$response1 = curl_exec($curl1);
$httpCode = curl_getinfo($curl1, CURLINFO_HTTP_CODE);
if($httpCode == 200) {echo "<p style='font-size:50px; color:#AED6F1;'>TEXT<br></p>";
                             $phparrays = json_decode($response1, true);

                             foreach($phparrays as $phparray ) {
                                                          
                                                          echo "<p style='font-size:30px;'>"; echo $phparray['contactName']; echo "\n"; echo $phparray['ph$'];
                             }

}
$response2 = curl_exec($curl2);
$httpCode = curl_getinfo($curl2, CURLINFO_HTTP_CODE);
if($httpCode == 200) {

                             
                             
                         $phparrays2 = json_decode($response2, true);
                              
                                echo "<p style='font-size:30px;'>"; echo $phparrays2['credit']; echo "</p>";

                      }





?>
chorn
php-forum GURU
php-forum GURU
Posts: 653
Joined: Fri Apr 01, 2016 2:18 am

Mon Jan 06, 2020 1:21 am

on a blank page you should have a look in the error.log of your webserver.
Post Reply