M_cMoreland Posted July 27, 2011 Share Posted July 27, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243012-display-json-from-url/ Share on other sites More sharing options...
Pikachu2000 Posted July 27, 2011 Share Posted July 27, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/243012-display-json-from-url/#findComment-1248161 Share on other sites More sharing options...
sKunKbad Posted July 27, 2011 Share Posted July 27, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243012-display-json-from-url/#findComment-1248177 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.