Jump to content

Recommended Posts

OK I am a bit of newb so forgive me. However I am trying to create a page that I can send an ID to and display the JSON of a url this page builds a new url (for another domain) I want to display the JSON from the new url. 

 

CODE:

<?php

//Get Client IP and Set $client_ip 
//if ( isset($_SERVER["REMOTE_ADDR"]) )    { 
//$client_ip=$_SERVER["REMOTE_ADDR"]; 
//} else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) )    { 
//$client_ip=$_SERVER["HTTP_X_FORWARDED_FOR"]; 
//} else if ( isset($_SERVER["HTTP_CLIENT_IP"]) )    { 
//$client_ip=$_SERVER["HTTP_CLIENT_IP"];   
//} 
//Get listing ID from URL filter_input(INPUT_GET, 'listing_id', FILTER_SANITIZE_STRING);
$listing_id = '10100230';
$client_ip = '123.4.56.78';
//Set Static Variables
$publisher = 'test';
$format = 'JSON';
$placement = 'xpage';

//Create query_string array for URL
$query_string = array('listing_id' => $listing_id,
                      'placement' => $placement,
                      'client_ip' => $client_ip,
                      'publisher' => $publisher,
                      'format' => $format
                           
                      );

//Build url
$url = "http://api.citygridmedia.com/content/places/v2/detail?" .
        http_build_query($query_string, '', "&");


  print $url 

?>

Right now it works to build the url what do I need to do to pull the json from the new URL and display it in the same or another page?

 

Here is the URL that is built and it works in a browser.

 

http://api.citygridmedia.com/content/places/v2/detail?listing_id=10100230&placement=test_page&client_ip=123.4.56.78&publisher=test&format=JSON

 

MOD EDIT: code tags added.

Link to comment
https://forums.phpfreaks.com/topic/243012-display-json-from-url/
Share on other sites

If you are asking how to get the JSON, you could use an ajax/javascript approach, or use php's file_get_contents function. You could also use cURL. Once the json is returned, you would either deal with it though javascript if you choose that approach, or use php's json_decode function, which turns the json back into an array.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.