PHP - Json Decode Url
Hey guys i got an api and it returns :
[ $json = file_get_contents(URL); $data = json_decode($json,true); $Decoded = $data['id'][0]; HERE no mater what i put i get and error Undefined index: id in /home/handshak/public_html/XC/get2.php on line 9 echo "<pre>"; print_r($Decoded); exit; What type of json structure is that? EDIT: if i use:
$contents = file_get_contents($json); i get:
[14-Apr-2019 15:38:32 UTC] PHP Warning: file_get_contents([{"id":"1","package_name":"1 Month Full + Adult - 2 Devices","is_trial":"0","is_official":"1","trial_credits":"0","official_credits":"1","trial_duration":"24","trial_duration_in":"hours","official_duration":"1","official_duration_in":"months","groups":"[4,5,6,8]","bouquets":"[27]","can_gen_mag":"1","only_mag":"0","output_formats":"[1,2,3]","is_isplock":"0","max_connections":"2","is_restreamer":"0","force_server_id":"0","can_gen_e2":"1","only_e2":"0","forced_country":"","lock_device":"0"},{"id":"2","package_name" in /home/handshak/public_html/XC/get2.php on line 7 Similar TutorialsHello everyone, I'm new here. Amazing forum, I found some help in the past by searching google.
Now I am looking for some help with the following code, I use this code to grab a JSON Feed and list the items in my page, this code works fine to get all the items, but I need to limit the number of items, otherwise It will load more than 500 items in my page and never stop loading.
Is there a way to limit the number of items grabbed from the JSON Feed?
Let's say, list 50 items in page 1, another 50 in page 2 and so on?
<?php $data = file_get_contents('http://json-url.com/type=json'); $decode = json_decode($data, true); foreach($decode as $d) { if($d['status'] == true){ echo '<div class="div">'; echo '<a href="'.$d['item_url'].'">'; echo '<img src="'.$d['item_image']['jpeg_thumbnail'].'" />'; echo '<span>'.$d['item_name'].'</span>'; echo '</a>'; echo '</div>'; } } ?>Thanks! hi all i have some json that i want to decode and add to mysql could you give me some help? i need to add each of these as a row here is the json Code: [Select] [ { "DayNumber": 1, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "T22" }, { "DayNumber": 1, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10CBP1", "ClassDescription": "Programming ", "StaffID": 607388, "Room": "CY17" }, { "DayNumber": 1, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10CWA1", "ClassDescription": "Web Authoring", "StaffID": 607388, "Room": "CY34" }, { "DayNumber": 1, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 1, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10APX4", "ClassDescription": "Photography", "StaffID": 620143, "Room": "CY14" }, { "DayNumber": 2, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10GHZ6", "ClassDescription": "Hazard Geography", "StaffID": 608055, "Room": "S22" }, { "DayNumber": 2, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:45:00 AM", "DefinitionTimeTo": "10:35:00 AM", "ClassCode": "10GHZ6", "ClassDescription": "Hazard Geography", "StaffID": 608055, "Room": "S22" }, { "DayNumber": 2, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 2, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 2, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10AMS2", "ClassDescription": "Media Studies", "StaffID": 622915, "Room": "CY14" }, { "DayNumber": 2, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10P9D6", "ClassDescription": "Physical Development", "StaffID": 83, "Room": "G3" }, { "DayNumber": 3, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:30:00 AM", "DefinitionTimeTo": "9:25:00 AM", "ClassCode": "10P9D6", "ClassDescription": "Physical Development", "StaffID": 1455, "Room": "G3" }, { "DayNumber": 3, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:25:00 AM", "DefinitionTimeTo": "10:15:00 AM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "T22" }, { "DayNumber": 3, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:35:00 AM", "DefinitionTimeTo": "11:30:00 AM", "ClassCode": "10APX4", "ClassDescription": "Photography", "StaffID": 620143, "Room": "CY14" }, { "DayNumber": 3, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:30:00 AM", "DefinitionTimeTo": "12:15:00 PM", "ClassCode": "10CBP1", "ClassDescription": "Programming ", "StaffID": 607388, "Room": "CY17" }, { "DayNumber": 3, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10C9H1", "ClassDescription": "Chapel", "StaffID": 1071, "Room": "C1" }, { "DayNumber": 3, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "A3" }, { "DayNumber": 4, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10QCS5", "ClassDescription": "Literacy - Curriculum Support2", "StaffID": 601807, "Room": "A1" }, { "DayNumber": 4, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:45:00 AM", "DefinitionTimeTo": "10:35:00 AM", "ClassCode": "10QCS5", "ClassDescription": "Literacy - Curriculum Support2", "StaffID": 601807, "Room": "A1" }, { "DayNumber": 4, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10AMS2", "ClassDescription": "Media Studies", "StaffID": 622915, "Room": "CY14" }, { "DayNumber": 4, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10AMS2", "ClassDescription": "Media Studies", "StaffID": 622915, "Room": "CY14" }, { "DayNumber": 4, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 5, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 5, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:45:00 AM", "DefinitionTimeTo": "10:35:00 AM", "ClassCode": "10CWA1", "ClassDescription": "Web Authoring", "StaffID": 607388, "Room": "CY34" }, { "DayNumber": 5, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10GHZ6", "ClassDescription": "Hazard Geography", "StaffID": 608055, "Room": "S22" }, { "DayNumber": 5, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "T22" }, { "DayNumber": 5, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10QCS5", "ClassDescription": "Literacy - Curriculum Support2", "StaffID": 601807, "Room": "A1" }, { "DayNumber": 6, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 6, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:45:00 AM", "DefinitionTimeTo": "10:35:00 AM", "ClassCode": "10CBP1", "ClassDescription": "Programming ", "StaffID": 607388, "Room": "CY17" }, { "DayNumber": 6, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10C9H1", "ClassDescription": "Chapel", "StaffID": 1071, "Room": "C1" }, { "DayNumber": 6, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10CWA1", "ClassDescription": "Web Authoring", "StaffID": 607388, "Room": "CY34" }, { "DayNumber": 6, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10APX4", "ClassDescription": "Photography", "StaffID": 620143, "Room": "CY14" }, { "DayNumber": 6, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "T22" }, { "DayNumber": 7, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10CWA1", "ClassDescription": "Web Authoring", "StaffID": 607388, "Room": "CY34" }, { "DayNumber": 7, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10CWA1", "ClassDescription": "Web Authoring", "StaffID": 607388, "Room": "CY34" }, { "DayNumber": 7, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10P9D6", "ClassDescription": "Physical Development", "StaffID": 1455, "Room": "G3" }, { "DayNumber": 7, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10GHZ6", "ClassDescription": "Hazard Geography", "StaffID": 608055, "Room": "S22" }, { "DayNumber": 8, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:30:00 AM", "DefinitionTimeTo": "9:25:00 AM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "S21" }, { "DayNumber": 8, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:25:00 AM", "DefinitionTimeTo": "10:15:00 AM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "S21" }, { "DayNumber": 8, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:35:00 AM", "DefinitionTimeTo": "11:30:00 AM", "ClassCode": "10APX4", "ClassDescription": "Photography", "StaffID": 620143, "Room": "CY14" }, { "DayNumber": 8, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:30:00 AM", "DefinitionTimeTo": "12:15:00 PM", "ClassCode": "10APX4", "ClassDescription": "Photography", "StaffID": 620143, "Room": "CY14" }, { "DayNumber": 8, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10QCS5", "ClassDescription": "Literacy - Curriculum Support2", "StaffID": 601807, "Room": "A1" }, { "DayNumber": 8, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10AMS2", "ClassDescription": "Media Studies", "StaffID": 622915, "Room": "CY14" }, { "DayNumber": 9, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10P9D6", "ClassDescription": "Physical Development", "StaffID": 83, "Room": "G3" }, { "DayNumber": 9, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:45:00 AM", "DefinitionTimeTo": "10:35:00 AM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "T22" }, { "DayNumber": 9, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10CBP1", "ClassDescription": "Programming ", "StaffID": 607388, "Room": "CY17" }, { "DayNumber": 9, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10CBP1", "ClassDescription": "Programming ", "StaffID": 607388, "Room": "CY17" }, { "DayNumber": 9, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 9, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "S23" }, { "DayNumber": 10, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10GHZ6", "ClassDescription": "Hazard Geography", "StaffID": 608055, "Room": "S22" }, { "DayNumber": 10, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:45:00 AM", "DefinitionTimeTo": "10:35:00 AM", "ClassCode": "10F9M1", "ClassDescription": "Form Period", "StaffID": 615792, "Room": "T11" }, { "DayNumber": 10, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 10, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10AMS2", "ClassDescription": "Media Studies", "StaffID": 622915, "Room": "CY14" }, { "DayNumber": 10, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10QCS5", "ClassDescription": "Literacy - Curriculum Support2", "StaffID": 601807, "Room": "A1" }, { "DayNumber": 10, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "T22" } ] thanks Matt I am having a nightmare sending / recieving some JSON..... I have a test page which creates a JSON packet and posts it to another page. This page then processes it and returns a response... the data is in the post, but after decoding it the data seems to be lost.... Here is the code for the sending page: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <?php require_once ("inc/jsonwrapper/JSON/JSON.php"); $RequestID ='121'; // :ID to which this request relates to allow site to keep track of things $Method = 'login'; //:Which method the call is directed at $referer = 'abc'; // :Name of referring network $affiliateid =2468; // :ID of referring site in affiliate network if any $user_Country ='gb'; // :Users two letter country code $UserID = '12345'; // :Numeric ID to identify players in game database belonging to network or portal $GameuserID = '1' ; // UserID in game database $params = array ( 'referer' => $referer , 'affiliateid' => $affiliateid , 'userCountry' => $user_Country , 'UserID' => $UserID , 'GameuserID' => $GameuserID); $response = array ( 'jsonrpc'=>'2.0', 'id'=> $RequestID , 'Method' => $Method , 'params' => $params) ; $data = json_encode($response); // URL of web api page $url = 'http://xxx.com/webapi.php'; $reply = do_post_request($url, $data); // setup new JSON service $json = new Services_JSON(); $jsonPacket = $json->decode($reply,true); //THIS IS WHERE I PRINT THE RESPONSE echo print_r ($jsonPacket,1); function do_post_request($url, $data, $optional_headers = null) { $params = array('http' => array( 'method' => 'POST', 'header'=>"Content-Type: text/xml; charset=utf-8", 'content' => $data )); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response; } ?> And the replying page Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <? //setup database connection require_once('globals.php'); //setup JSON require_once ("inc/jsonwrapper/JSON/JSON.php"); $secret_Key = '12345';//SECRET KEY $app_Id = '6789';//APP ID $token = ''; // setup new JSON service $json = new Services_JSON(); // accept incoming POST data $input = $GLOBALS['HTTP_RAW_POST_DATA']; //hashes $hash = $_GET['authHash']; $sHash = strtolower(md5($input . $secret_Key)); $hash = 0; $sHash = 0; if (strcmp($sHash, $hash) == 0) { //check if incoming is JSON as we MIGHT use XML later too $isJSON= substr_count($input,"json"); if ($isJSON > 0){ processJSON ($input); } global $hash, $sHash; } //JSON FUNCTION TO PARSE JSON function processJSON($input){ global $json; $jsonPacket = $json->decode($input,true); $json_RequestId = $jsonPacket->id; //check method and go to correct function switch ($jsonPacket->Method){ case 'Game.login': game_login ($jsonPacket, $json_RequestId) ; break; } } //JSON FUNCTIONS function game_login($jsonPacket, $json_RequestId){ $aid = ($jsonPacket->params->affiliateid); $country_code = ($jsonPacket->params->userCountry); $GameuserID = ($jsonPacket->params->GameuserID); $UserID = ($jsonPacket->params->UserID); //mail ("martyn@staggan.com" , "SNSUserID" , $UserID ); $result_userIDcheck = mysql_query("SELECT snsUserid FROM player where player_id = $GameuserID;"); $result_UserID = mysql_result ($result_userIDcheck, 0); if ($UserID == $result_UserID){ $result = 'OK'; $id = $json_RequestId; //create token global $secret_Key ; $token = hash ('md5', $secret_Key.$aid.$GameuserID); $logindetails = array ( 'token=' => $token , 'UID'=> $GameuserID , 'snsUID' => $UserID , 'aid' => $aid , 'name' => $name); $params= array ('result'=>$result, 'logindetails'=> $logindetails, 'GameuserID'=>$GameuserID); $response = array ( 'jsonrpc'=>'2.0', 'id'=> $id , 'result' => $params) ; echo json_encode($response); } else mail ("test@test.com", "login", 'false'); } ?> If I print the $reply var I see this: {"jsonrpc":"2.0","id":"121","result":{"result":"OK","logindetails":{"token=":"68c49918c353a3e5d86d165da1cb2f72","UID":"1","snsUID":"12345","aid":"6789","name":null},"GameuserID":"1"}} But trying to decode to an array leaves me with nothing.... Any help would be greatly appreciated Hi all,
I'm posting JSON to an API call. If I use a var_dump within the API it will return correctly, although if I try to var_dump within the function it will return NULL.
API:
$json = file_get_contents('php://input'); if(isset($_GET['form_id']) && intval($_GET['form_id'])>0) { if(isset($json)) { $records = $questionnaire->logFormAnswers($_POST['answers'],$_GET['form_id']);Then using the logFormAnswers function... Function: public function logFormAnswers($answers = "", $form_id = 0) { $answers = json_decode($json,true); var_dump($answers);The JSON: [{"question_id":"3","answer":"dsf"},{"question_id":"3","answer":"sdfsdfdsfsd"}]Eventually, once the JSON has been decoded, it will be inserted into a database within the function. I am using multiple levels of JSON data coming into php from a C# application, as in:
return new RootObject() { ID_Project = 4, Name_Project = "Test", Receiver_ID = 4, Receiver_Name = "ABCDE", UserID = 20, UserRole = new User_Role() { ID_User = 20, Role_User = "level 3", User_Role_Description = "U", UserGroup = new List<user_group>() { new User_Group() { ID_UserGroup = 30, Name_UserGroup = "usergroup8", UserID = 20 }, new User_Group() { ID_UserGroup = 31, Name_UserGroup = "usergroup9", UserID = 21 }, new User_Group() { ID_UserGroup = 32, Name_UserGroup = "usergroup10", UserID = 22 } } } }; i am having troubles accessing the second level: UserRole and 3rd level: User_Group in my php script. im currently trying like this: foreach ($phpArray as $key => $value) { echo "<h2>$key</h2>"; foreach ($value as $k => $v) { echo "$k | $v "; foreach ($v as $key1) { echo "$key1 "; } } } does anyone have an idea? Thanks, Revathy This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=323713.0 How to decode this? Code: [Select] http://www.mediafire.com/?niwske5oy33wzrz need help I have implemented the base64_encode() function with some custom mapping table so I could encode some binary data more securely without anyone knowing how to decode it here is the class <?php class Base64 { /** * I have changed letter placement (P <=> x, S <=> 9) and the cases * You can completely redo the mapping table */ private static $BinaryMap = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', // 7 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'x', // 15 'q', 'r', '9', 't', 'u', 'v', 'w', 'x', // 23 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', // 31 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', // 39 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', // 47 'W', 'P', 'Y', 'Z', '0', '1', '2', '3', // 55 '4', '5', '6', '7', '8', 'S', '+', '/', // 63 '=', // padding char ); public function __construct() {} public function base64_encode($input) { $output = ""; $chr1 = $chr2 = $chr3 = $enc1 = $enc2 = $enc3 = $enc4 = null; $i = 0; // $input = self::utf8_encode($input); while($i < strlen($input)) { $chr1 = ord($input[$i++]); $chr2 = ord($input[$i++]); $chr3 = ord($input[$i++]); $enc1 = $chr1 >> 2; $enc2 = (($chr1 & 3) << 4) | ($chr2 >> 4); $enc3 = (($chr2 & 15) << 2) | ($chr3 >> 6); $enc4 = $chr3 & 63; if (is_nan($chr2)) { $enc3 = $enc4 = 64; } else if (is_nan($chr3)) { $enc4 = 64; } $output .= self::$BinaryMap[$enc1] . self::$BinaryMap[$enc2] . self::$BinaryMap[$enc3] . self::$BinaryMap[$enc4]; } return $output; } public function utf8_encode($input) { $utftext = null; for ($n = 0; $n < strlen($input); $n++) { $c = ord($input[$n]); if ($c < 128) { $utftext .= chr($c); } else if (($c > 128) && ($c < 2048)) { $utftext .= chr(($c >> 6) | 192); $utftext .= chr(($c & 63) | 128); } else { $utftext .= chr(($c >> 12) | 224); $utftext .= chr((($c & 6) & 63) | 128); $utftext .= chr(($c & 63) | 128); } } return $utftext; } } ?> and the usage as follows: <?php $string = pack('H*', "31c85c5aaa56c1f0102301ea497d0ab010e4e131af261787"); //HEX echo Base64::base64_encode($string); echo "<br />"; echo base64_encode($string); ?> and the output will be: mCHCwQPwWFaqiWhQ9x0kSbdK4tgVjHEh // with custom mapping MchcWqpWwfAQIwHqSX0KsBDk4TGvJheH // the base64_encode() I need help how to decode the this key I need to know how to decode it <?php echo "\x61s\144as\x61s\x64"; ?> ---------------------------------- This is what was encoded: <?php echo "asdasasd"; ?> i know of Bace64 rot_13 is thare more than just this? (for urls) Hi all, Firstly, i apologise for the long post, but I wanted to give you an overall feel for what I am trying to achieve. The question is at the end!! My Plan is to take emails and stores these in MySql for late retrieval and display. The email could be plain text or html and may contain any number of file attachments (or none)! I have no problem getting the email or saving it into SQL, but my problem is decoding it and extracting any attachments. Ultimately in the SQL database I will have all the usual parts (To, From, etc) plus the body of the email (plain and/or html) and a list of attachments. Everything I have read so far involves getting the emails from an iMap mail server however my emails are all contained in individual text files. My question is really to enquiry what classes/scripts are available to help me decode the text file (email) and gather all the information I need. Any help or pointers much appreciated Thanks David Hi, Im trying to use base64_decode on a string, however the string is sometimes plain text others its encoded, how can i test to see if the sting is encoded or plaintext and only perform the decode if the string is indeed encoded? Im pretty new to PHP, but ive seen mentions of regex or preg_match for certain characteristics of base64 encoded, my one observation is it usually ends in == which wouldnt appear in my plain text, could i do a preg match for that? This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=330778.0 So I encode and decode html entities of my thread body variable in my script but now that I am working on the quote function I realize even after decode it prints the html entities instead of the regular character is there anyway to change this because if not it is going to print my font tag as characters instead of the font tag actually doing its job. Thanks! P.S. if this double posts I don't know what's going on...it happened last time but I didn't double post. It may be that I am using a mobile phone. hi i have this code: Code: [Select] //sql $sql -> bind_param('s',$offer); $sql -> execute(); $sql -> bind_result($oferta, $cargo, $conteudo, $tipo_oferta, $local); $arr = array(); while ($sql -> fetch()) { $arr[] = array($oferta, $cargo, $conteudo, $tipo_oferta, $local); }; return $arr; then i make this in ajax (jquery) Code: [Select] data: 'all=<?php echo json_encode($arr); ?>', and in other page i make: Code: [Select] $editar = $_POST['all']; $e = json_decode($editar, true); echo $e[0][0]; the problem is: if i only do : Code: [Select] $arr[] = array($oferta); this echo $e[0][0]; outputs: designer (is the value of $oferta) but if i do Code: [Select] $arr[] = array($oferta, $cargo, $conteudo, $tipo_oferta, $local); echo $e[0][0]; simply doesn't show anything. the question is why ? and how can be solved? im trying to access code in Code: [Select] array(1) { [0]=> object(stdClass)#4 (1) { ["error"]=> array(1) { [0]=> object(stdClass)#5 (2) { ["message"]=> string(33) "no results found (error code 458)" ["code"]=> string(3) "458" } } } } ive tryed echo $blog_posts[0]->error->code; but all i get is Notice: Trying to get property of non-object in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 173 Hi, I have two select boxes on my site like this: Language - Level and the user can keep adding more sets of select boxes. I need the data posted to be JSON encoded like this: {"LANG1":["German","Beginner"],"LANG2":["Polish","Advanced"]} etc How can i make this happen? Please see http://www.socialnewsoffice.com/blog_posts?&display=2&api_key=b5cbd66dca99c49d1a6c3d which out puts a json response like this Code: [Select] [{ "blog_id":"3", "post_date":"Sat, 14 April 2012", "post_title":"Facebook's New Fan Page Learn How To Use Features", "article_img":"http:\/\/www.socialnewsoffice.com\/uploads\/17963.jpg", "post_content":"<p>This week saw the release of Facebook's latest functionality changes (Timeline for Businesses) that will shape the future of how businesses will market their campaigns, through the social media giant Facebook. A number of marketers are wondering how they will incorporate the new features in an attempt to progress and move forward with their online social media presence.<\/p>\r\n<p>Taking all the key changes in to consideration we have managed to create a guide on how to smoothly move with the times and embrace the new Facebook layout.<\/p>\r\n<p>Please read on below for helpful tips and tricks on how to excel with 'Timeline for Brands'<\/p>\r\n<h2>New Features Announced at the Facebook Marketing Conference:<\/h2>\r\n<p><strong>View and Apps:<\/strong> What was once known as Application pages has changed to 'Tabs'. These can now have customizable images linked with them and the order of them can be changed too. Below you can see from the screenshot what a customized Facebook Timeline looks like.<\/p>\r\n<p><strong>Pinning Content:<\/strong> With this new feature you can 'pin' a post to the very top of your Facebook Timeline. This is Very effective when working on a new campaign and is a great way to entice increased traffic to your tab or application page.<\/p>\r\n<p><strong>Featured 'Starred' Content:<\/strong> This feature allows you to select key content or imagery and extend it so it fits across your entire page. Therefore giving you featured content on your Facebook Timeline and making it more visible.<\/p>\r\n<p><strong>Cover Photos:<\/strong> Cover Photos are another great new feature that allow you to announce your latest campaign, welcome your following community or just simply show visitors to your timeline what you can do. There are some slight flaws with this feature though and will be addressed below.<\/p>\r\n<p><strong>Page Dimensions:<\/strong> Dimensions of application pages has now changed with the release of Facebook Timeline. If you happen to be an SML user then you have all the tools necessary to update your page on your own. If your using Involvers App Suite then those applications will be updated soon.<\/p>\r\n<p><strong>Removal of Default Landing Pages:<\/strong> The commonly used Facebook landing pages have been removed and replaced with various options to allow brands to drive content to application pages. These options allow you to use your cover photo and pinned content to attract users to your personal application pages. Despite the changes it is however still possible to link directly to application pages from ads, posts and outside of Facebook.<\/p>\r\n<h2>Getting Started with Timeline For Brand:<\/h2>\r\n<p>Firstly when accessing and logging in to your New Facebook Brand Page, you will see this admin message displayed below:<\/p>\r\n<p>When will my Page change to the latest design?<\/p>\r\n<p>To see a preview of what your new pages will look like, simply click on the green button at the top of your current pages. A second option is to wait until March 30th 2012 when all pages will be upgraded automatically.<\/p>\r\n<p>Where can I visit to learn more about how to use the new Pages?<\/p>\r\n<p><strong>There are a number of places you can visit to learn all you need to know about Pages:<\/strong><\/p>\r\n<ul>\r\n<li>To find out more about new features, download the Pages Overview guide by clicking here.<\/li>\r\n<li>If your wondering how to get started with Pages then download Facebook's full Pages Product Guide by clicking here.<\/li>\r\n<li>The Pages Learning video allows you to walk through the key features with Facebook's product experts.<\/li>\r\n<li>If you need answers to specific questions, visit Facebook's Help Centre.<\/li>\r\n<\/ul>\r\n<h2>How should I choose a cover photo for my Page?<\/h2>\r\n<p>Firstly select a unique image that represents your page. Facebook itself recommends using a photo of a popular menu item, album artwork or an image of your product being used by someone. You need to experiment with a number of different images that your audience responds positively to. Few key elements of Cover Images:<\/p>\r\n<p><strong>Each Cover image must be at least 399 pixels wide and must not contain the following:<\/strong><\/p>\r\n<ul>\r\n<li>Prices \/ Purchase information and displaying offers such as \"60% off this month\" are not permitted. Also 'Download this from our website' is not allowed.<\/li>\r\n<li>No email addresses, web addresses and any other contact information.<\/li>\r\n<li>References to clicking on or the use of Facebook interface elements such as Like or Share or any other Facebook Features.<\/li>\r\n<li>\"Tell your friends\" or \"Get it now\" or any other calls to action are not allowed in the latest version of Facebook Timeline.<\/li>\r\n<\/ul>\r\n<p>All Timeline cover imagery is public and therefore means anyone visiting your Page will be able to see exactly which image you have chosen. The photos you display must not be deceptive, false or misleading any way that infringes on third party intellectual property. You must also not encourage of incentivize other fellow users, friends or business associates to display the same cover image as yours on personal Timelines.<\/p>\r\n<p>To sum up we are extremely excited about the latest Facebook feature release this week. They constantly deliver new services that are amazing and incredibly innovative to the market place.<\/p>\r\n<p>Here at Northplanet we are commited to provide you with the latest information on the hottest online topics around, to keep you ahead in the game. We would love to hear some feedback from you on the brand new Facebook 'Timeline for Brands' release and invite you to visit our very own <a href=\"https:\/\/www.facebook.com\/northplanet\">Northplanet Facebook Timline page by clicking here.<\/a><\/p>", "tags":"facebook, new fan page", "views":"463", "categorie_id":"2", "post_url":"facebooks-new-fan-page-learn-how-to-use-features" },{ "blog_id":"2", "post_date":"Mon, 23 January 2012", "post_title":"Northplanet Engages New Talent!", "article_img":"http:\/\/www.socialnewsoffice.com\/uploads\/1263.jpg", "post_content":"<p>Big piece of news for the start of 2012 is…… I have landed a full time role in a leading Web Design and Development agency based in Greater Manchester. After a successful interview on New Years Eve, I had another reason to celebrate bringing in the New Year!!<\/p>\r\n<p>I was first attracted to Northplanet when I came across there website when searching for jobs online. I was impressed not only by the standard of web work but the direction the company where going in. Growing year by year and providing exceptional web solutions for a number of businesses spread across the UK.<\/p>\r\n<p>I contacted them instantly and have done some freelance work a few times in the last year for Directors Danny and Mike and was able to build up a strong working relationship that helped me land the interview at the end of the year.<\/p>\r\n<p>I begin my career at Northplanet next week and will post all offers\/promotions and deals on here in the nearfuture.<\/p>\r\n<p>Time to sign off and prepare for my new career!!<\/p>", "tags":"engages new talent, new staff, northplanet staff, christian thomas mizon", "views":"271", "categorie_id":"1", "post_url":"northplanet-engages-new-talent" }] here is my code that does this Code: [Select] if (mysqli_num_rows($r) > 0) { // Available. while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $results[] = array( 'blog_id' => ($row['ID']), 'post_date' => ($row['pd']), 'post_title' => (html_entity_decode($row['post_title'], ENT_QUOTES)), 'article_img' => ('http://www.socialnewsoffice.com/uploads/'.$row['article_img']), 'post_content' => ($row['post_content']), 'tags' => ($row['tags']), 'views' => ($row['views']), 'categorie_id' => ($row['categorie_id']), 'post_url' => ($row['post_url'])); } echo $json = Pretty_JSON(json_encode($results)); } i can access the json by using foreach($blog_posts as $post) { however what i need to do is add a value to the json like pages => 2 how could i do this? My script is not acting like it should. I believe its because of the recent change in the api, (the new error array)? Before there was only one.... <?php $gamertag = 'l RaH l'; $url = "http://api.xboxleaders.com/user_api.php?gamertag=".str_replace(' ', '%20', $gamertag); $output = file_get_contents($url); // try to convert the response into a PHP object $obj = json_decode($output); if(!is_object($obj)) die("Error parsing JSON response\n"); //define variables $avatar = ($obj->user->avatar); $gold = ($obj->user->gold); print $avatar; print $gold; ?> if you print_r $object; it displays this {"error":{"code":200,"desc":"OK"}},{"user":{"gold":1,"gamertag":"l RaH l","avatar":"http:\/\/avatar.xboxlive.com\/avatar\/l%20RaH%20l\/avatarpic-l.png","gamerscore":12508,"reputation":20},"recent_games":[{"recent_game":{"title":"Halo: Reach","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1297287259&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/ih\/ew\/0Wdsb2JhbA9ECgR8GgMfVlohL2ljb24vMC84MDAwIAAAAAAAAP6fF5U=.jpg"}},{"recent_game":{"title":"Halo 3","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1297287142&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/Us\/3e\/1Wdsb2JhbA9ECgR8GgMfWSpVL2ljb24vMC84MDAwIAAAAAAAAPrxzU0=.jpg"}},{"recent_game":{"title":"AC Brotherhood","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1431504989&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/oK\/tp\/1Wdsb2JhbA9ECgUNGgMfVlonL2ljb24vMC84MDAwIAAAAAAAAPpGq78=.jpg"}},{"recent_game":{"title":"Fighters Uncaged","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1431504974&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/v+\/Au\/0Wdsb2JhbA9ECgUNGgMfVlsmL2ljb24vMC84MDAwIAAAAAAAAP4B4KA=.jpg"}},{"recent_game":{"title":"Assassin's Creed","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1431504852&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/L3\/mu\/0Wdsb2JhbA9ECgUNGgMfWStXL2ljb24vMC84MDAwIAAAAAAAAP6BeTA=.jpg"}}]} |