please help me.
this is the php code:
<?php
$path_to_file = 'https://kamboz.000webhostapp.com/OurGrocery/OurItemsGet/all_items.php';
$file_contents = file_get_contents($path_to_file);
$json = json_decode($file_contents);
foreach ($json->data as $item) {
echo $item->id;
}
?>
when i run this it shows this error:
Notice: Trying to get property 'data' of non-object in /storage/ssd4/665/18079665/public_html/OurGrocery/TESTING_FOLDER/testing.php on line 28
Warning: Invalid argument supplied for foreach() in /storage/ssd4/665/18079665/public_html/OurGrocery/TESTING_FOLDER/testing.php on line 28
this is the json link: https://kamboz.000webhostapp.com/OurGrocery/OurItemsGet/all_items.php
all things are good. checked it manually and use many websites for chcek json is valid or not. it is valid. but i think it is 'not a object' error. please anyone help me.
The JSON generated on this page is, as per the previous comment, not valid. Using json_decode on the seemingly good string will yield NULL because of various faults in the encoding. There are various faults with the data which should have been fixed using json_encode though perhaps the newlines would require further tweaks beforehand.
Using a regex to replace certain patterns on the above (sortof) json string allows the data to be parsed correctly
// fetch the "broken" JSON string
$url='https://kamboz.000webhostapp.com/OurGrocery/OurItemsGet/all_items.php';
$content=file_get_contents( $url );
// patterns of "broken" json to look for
$pttns=array(
'#\r\n\r\n"#m',
'#\s?\r\n\s?(\w)#m',
'#\r\n\s?"#m'
);
// replace matches with these
$replacements=array(
'"',
'$1',
'"'
);
// do the string fudging
$content=preg_replace( $pttns, $replacements, $content );
// now decoding json **should** be ok (?)
$json=json_decode( $content );
if( is_null( $json ) )echo 'Bad JSON';
else{
$data=$json->data;
// process the json data however you need.
printf('<h1>It works now... <span style="color:red">%s</span></h1>',$data[0]->name);
foreach( $data as $i => $obj ){
printf('<h2>Record: #%d</h2><pre>%s</pre>',$i,print_r($obj,true));
}
}
This yields:
It works now... Colgate Active Salt Tooth Paste 100g TUBE
Record: #0
stdClass Object
(
[id] => 1
[img_url] => https://kamboz.000webhostapp.com/OurGrocery/img_product/1.png
[name] => Colgate Active Salt Tooth Paste 100g TUBE
[category] => Colgate Active Salt Tooth Paste 100g TUBE
[description] => good quality.
[description_full] => this is Colgate Active Salt Tooth Paste 100g TUBE. you can use it in your daily life.
[rating] => 5.0
[discount] => 7
[price] => 64.32
)
Record: #1
stdClass Object
(
[id] => 2
[img_url] => https://kamboz.000webhostapp.com/OurGrocery/img_product/2.png
[name] => Colgate Active Salt 200gm TUBE
[category] => Colgate Active Salt 200gm TUBE
[description] => good quality.
[description_full] => this is Colgate Active Salt 200gm TUBE. you can use it in your daily life.
[rating] => 5.0
[discount] => 4
[price] => 111.82
)
Record: #2
stdClass Object
(
[id] => 3
[img_url] => https://kamboz.000webhostapp.com/OurGrocery/img_product/3.png
[name] => Patanjali DISH WASH BAR
[category] => Patanjali DISH WASH BAR shabun sabun sabn
[description] => good quality.
[description_full] => this is Patanjali DISH WASH BAR. you can use it in your daily life.
[rating] => 5.0
[discount] => 5
[price] => 9.99
)
None of that string fudging would be necessary if the JSON were properly generated initially and this does not constitute a robust solution - focus on creating valid json initally and the rest is simple.
Related
I have a problem with some third party php scripts not decoding properly using xampp on windows 7. The process is that the script sends an encrypted payload to an external server where it is decrypted and returned. We have no access or control of the external server. The relevant code is:
$response = $provider->request('package/decode/' . $endpoint, 'POST', $params);
$data = $response->toXml();
if (isset($data->object)) {
$object = (string)$data->object;
$object = base64_decode($object);
$object = unserialize($object);
}
if (isset($data->related_objects)) {
$relatedObjects = (string)$data->related_objects;
$relatedObjects = base64_decode($relatedObjects);
$relatedObjects = unserialize($relatedObjects);
}
The $object decodes with no problem. The $relatedObjects does not and looks corrupt part way through:
YToxOntzOjEyOiJQbHVnaW5FdmVudHMiO2E6MTA6e3M6MzI6ImQ0NzM2NzJjM2YyNzk2NjVhYTNmNWJlNjBjMzU2MjYyIjthOjg6e3M6MTM6InByZXNlcnZlX2tleXMiO2I6MTtzOjEzOiJ1cGRhdGVfb2JqZWN0IjtiOjA7czoxMDoidW5pcXVlX2tleSI7YToyOntpOjA7czo4OiJwbHVnaW5pZCI7aToxO3M6NToiZXZlbnQiO31zOjU6ImNsYXNzIjtzOjE0Oi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SzvpaVVmN7uQRwPqOsNakBPjdz4ibEN0ZYpuoYDlJos/VxhlNi/KLbFosufeEXbqDx5eSWYl6BNRgnB2+qX/AO+hNuanN4Y711Sx8AJReInSUlgCG1QPrej7ZAYp+v1j1+i3oQw45Qtm2gBmFmWlMU4moDXZHwYNK0+OUfggZ8IESROYL85bQft+IvQMqGodgdEFY0ztWB3EItOVW6wS21HpMJ8CKJdqGFRSPuq9qoewjqRFkduG/Vnn1xib1tWz3OpILecoCCLehiaFN+rWX5ZN7cw3acJRq29oILLaw/I7teu119ASNo3J2OjJ1Ct6QYJB0FSa5Jsr4EhnZaf0r6VI7MM7aOAe1XMOXP0F2ks1Ash057XMxLdkdB8EKGQPm4w0aYxRbRoY4UK8nxERZHyxb4XpxIfN1mHXMV2TalbyyxB3dMLK80csIPzRRPdpvUnFRNynw1ZaJUrypTZfWBnf2eNbT6ynWrWmrBR5+jKuOwevGidfh5tE6U4prLU8as+/ARq/E4TfVfjUesfDSbyRqd/FDxpHeI3pVTwW4gsA==
Result:
a:1:{s:12:"PluginEvents";a:10:{s:32:"d473672c3f279665aa3f5be60c356262";a:8:{s:13:"preserve_keys";b:1;s:13:"update_object";b:0;s:10:"unique_key";a:2:{i:0;s:8:"pluginid";i:1;s:5:"event";}s:5:"class";s:14:"modPluginEvent";s:6:"object";s:75:"{"pluginid":0,"event":"OnRichTextBrowserInit","priority":0,"propertyset":0}";s:4:"guid";s:32:"003311160d090c51cac7a9388d4303b7";s:10:"native_key";a:2:{i:0;i:0;i:1;s:21:"OnRichTextBrowserInit";}s:9:"signature";s:32:"d5ab9f15c9f783de2a41b36c19d1504d";}s:32:"7c73e878b936b94f0d3fea62a7230c43";a:8:{s:13:"preserve_keys";b:1;s:13:"update_object";b:0;s:10:"unique_key";a:2:{i:0;s:8:"pluginid";i:1;s:5:"event";}s:5:"class";s:14:"modPluginEvent";s:6:"object";s:79:"{"pluginid":0,"event":"OnManagerPageBeforeRender","priority":0,"propertyset":0}";s:4:"guid";s:32:"6d17c04ae92648e5359425b8295e39d5";s:10:"native_key";a:2:{i:0;i:0;i:1;s:25:"OnManagerPageBeforeRender";}s:9:"signature";s:32:"d62c754c7913c8e5175cd35a52f1e30d";}s:32:"6e514b51604cf37f846e677e9c5ac090";a:8:{s:13:"preserve_keys";b:1;s:13:"update_object";b:0;s:10:"unique_key";a:2:{i:0;s:8:"pluginid";i:1;s:5:"event";}s:5:"class";s:14:"modPluginEvent";s:6:"object";s:72:"{"pluginid":0,"event":"OnDocFormPrerender","priority":0,"propertyset":0}";s:4:"guid";s:32:"e640fc3f94527491ddf75737e1002660";s:10:"native_key";a:2:{i:0;i:0;i:1;s:18:"OnDocFormPrerender";}s:9:"signature";s:32:"9c60acab8448b8e13028015685315c6b";}s:32:"086ee225189c2ef7f680bd5ae64b4964";a:8:{s:13:"preserve_keys";b:1;s:13:"update_object";b:0;s:10:"unique_key";a:2:{i:0;s:8:"pluginid";i:1;s:5:"event";}s:5:"class";s:14:"modPluginEvent";s:6:"object";s:78:"{"pluginid":0,"event":"OnRichTextEditorRegister","priority":0,"propertyset":0}";s:4:"guid";s:32:"c45d58e9fed5d9472e9f011056b3a087";s:10:"native_key";a:2:{i:0;i:0;i:1;s:24:"OnRichTextEditorRegister";}s:9:"signature";s:32:"11bed8b8f2ed19a2e5dfa0af625542f9";}s:32:"b28ade7c448fdc2bd37ee0e4d4812115";a:8:{s:13:"preserve_keys";b:1;s:13:"update_object";b:0;s:10:"unique_key";a:2:{i:0;s:8:"pluginid";i:1;s:5:"event";}s:5:"class";s:14:"modPluginEvent";s:6:"object";s:73:"{"pluginid":0,"event":"OnTVInputRenderList","priority":0,"propertyset":0}";s:4:"guid";s:32:"f851e497fd89d0bcf804f4efd4f95e2c";s:10:"native_key";a:2:{i:0;i:0;i:1;s:19:"OnTVInputRenderList";}s:9:"signature";s:32:"c7c9a081e2ca8e28de695b2e0c3738a0";}s:32:"2091d8ae247ff47402276e84e0467d30";a:8:{s:13:"preserve_keys";b:1;s:13:"update_object";b:0;s:10:"unique_key";a:2:{i:0;s:8:"pluginid";i:1;s:5:"event";}s:5:"class";s:14:"modPluginEvent";s:6:"object";s:74:"{"pluginid":0,"event":"OnTVOutputeØ
f+}]²ÄÈrõzÉ6v6{ÕEôãüwÙ\°ÈÛXsOÔ0ñ]9TéNµªq91õxñ!|
ü·ñs.1ÅhÜåÃèBù³õª5
R¸+mxGÑÂnÜÇOjÇ8ï?Þ¥ãä½ÉJ©fµ÷^½Q#Ý3Ò2ËgdDcöRiÕTÿËp°ðÿÿ2ö?ñ±ÊëeMÔIö0Ei0°Où¦³yåaÕg?¿Î¨Lá?!L÷ Ø¿öëOé«â×('Y5Y¦{Zj¢·àÂpÍNúx¯áý,Îùün¾õñ0ë ¬Ãè}%µâ8(¤éPm9N¸J§Øq¾Ùïï5¼F}ÉõH9¨'1Å5¢È[ãReìî$o÷Ò)l£,·Jsßùݵ®g¤ìu;ÜXÏL
-Ñ©U>6\z¶Ó#úÑHöÍn¥À5ßa# 7¦Þ¤ðR=§?|ß8·úh +¤VÉ:©'Ä´&Þµ_4(ÚÒ¬º¤þ½ºäh°Áµ28ôɯÇ
Ñ·ö<d¡£ÀÝÞ"¿Q=£TÑÞÝ|¢iÙÂ7$åÓÂîTF«j7
¹õä"Ùh$|ìüõ(ÕNiB%j+¾<Tߣ&ØÙÃ-1ê0rÉúºJè/´
ª©íIáô®s2·*_Rõt¥»QÌuâÉAØ#ÒLLΰVuå*^ôÊ⥴²ëôEµ"þ)º ÈvÄ/§Fa!ÕRÇO6d×ìâ?j»ä¼¤û?q+h2¾e..ÄÛgbË-<&GOwérZ¬Ü$UI¥¤}òò¯óíÅ:Y©w¥Y|î3A=9à{ÅÆsè]ÕÚQ'zp+8âNðÑj1< 'fvº6.(ñ8hÝÎ(jóÀÞ|wAÃìH0éj8³÷û¶ (´ ÃjEÃêÉù(±Q*PãIñÔGUÚÊt}&«-ÙÝ<Î8)ÏqNùÝ7êÈÕ*${±ÛòØþ~Â3^ðo;NûRÄì»%5Ï®®u^-,7ä§_¢ÊÔ´(ÜÊMûOZ½ûòèGhðÉôrG¤|F+ÂéÐåü
h2¥=Øù\Ðë¾Îõ}ļ£f]¨ZòPÍ6½,ITaëb8ÏC®Ö!¬FÃ<n´Õð{-*dÃw"éÑKpþðÈY;>ï׫ªÆÄ ;ªT9qõk3à©;¡¸ªAði92·çc¦¾õQ´µV»áægÈt ºüwÑÄ8To0àß(7ãê¶ü&²\CÄéP%"õjw½ôAÅVDQ%Ñ%uºÞXõÊÇ_füÑüë;>½µ+ z[Þá»6WðXJÞl+v:ÒðÞÍA*H:²³÷6ÅÇýøÅ6A#Áõxq³IcCb©?÷yY³¿.O}6q¥Ù
°¨ÞuÄ7 ü7HJ
VlûáÞwg¥ýKw
¼3Uj&ü|wÒ=õ>ì9"8/9U~ê³Úq³põà}Èð¬(=§ ÏN®õ×è9¤¶}ûR7ûÔôMD=¾ÈµÐ)Âtv¶7VGëÛÄ
òô´uü8NÔãm¨Dxöáp½°
KþÒËÈÛwø<Ó½ËÑL&¾ÌpðjáÉ_c]Þ(²;¢òv÷aO*rÌ7 M1)tRÄwv¶!RkÔ'8îÝ_HG±{øKDÕ77²OWðüé{ké[uù^äÙû¹G¡.Kz¯RélÀo^øPßZ7ªQM¶Et)ì÷ÙÎ<à©y¶Z¦(ÖQ¬ÛܵimIùtÞM³ÁåÒD#QN¨.SêòÂÞü÷VùõÉpª¥¾®O.ɶ·öSuhqæMIÇ?ýv¼ñô®E²¹ÚãÁtI¬²Z:·ØGoEá5hcWûDáXÉ+*³¾Vc{¹p>£¬5©>7sâ&Ä7FX¦êRh³õqSbü¢Û.}án ñåäb^5'oª_ðúnjsxc½uK%%%!µ#úÞ¶#b¯Ö=~zÃP¶m afZSâj]ðÒ´øå| D9üå´·â/#Ê¡ØV4ÎÕÜB-9UºÁ-µ ð"v¡E#î«Ú¨{êDY¸oÕ}q½m[=ΤÞr-èbhS~eùdÞÜÃv%¶ö-¬?#»^»]}#hÜB·¤$I®I²¾vZJúTÌ3¶íW0åÏÐ]¤³P,N{\ÌKvGAðB#ù¸ÃFÅÑ¡+ÉñGËø^H|ÝfsÙ6¥o,±wL,¯4rÂÍOvÔTMÊ|5e¢T¯*Seõý5´úÊu«ZjÁG£*ã°zñ¢uøy´NâËSƬûð«ñ8Mõ_G¬|4ÉüPñ¤wÞSÁn °
There are no php errors or errors at the software providers end either. I have set Apache and PHPs charsets to UTF-8. I have the same script working on an external centos 7 setup and the vendor says other customers use xampp with no problem. So I'm guessing this is a local character encoding problem with windows or php? How can I to narrow it down so I can decode the string correctly? Thanks.
My first guess was that a piece of the data is missing, and because of the cyclic inner structure of base64 if we'd cut off at a different offset we could get the data back.
So I've tried:
echo base64_decode(substr($payload, $offset));
for different offsets around 3400 (where the corruption starts), and got no luck! At any offset it was still gibberish.
Then I tried collecting byte statistics to see if it's coherent to the distribution usually found in text files to which JSON belongs.
$pivot = 3400;
$decodeJson = base64_decode(substr($payload, 0, $pivot));
$decodeGibberish = base64_decode(substr($payload, $pivot));
print_r(getByteDistribution($decodeJson));
print str_repeat('-', 100) . "\n";
print_r(getByteDistribution($decodeGibberish));
function getByteDistribution(string $input): array {
$distribution = [];
for ($i = 0; $i < strlen($input); ++$i) {
$ord = ord($input[$i]);
if (!isset($distribution[$ord])) {
$distribution[$ord] = 0;
}
$distribution[$ord]++;
}
arsort($distribution, SORT_NUMERIC);
return $distribution;
}
And this is what I got:
Array
(
[58] => 281
[34] => 236
[101] => 181
[115] => 132
[59] => 129
[105] => 101
[48] => 88
[49] => 83
[116] => 76
[110] => 76
[97] => 70
[100] => 69
[50] => 66
[114] => 61
[51] => 60
[99] => 55
[53] => 52
[52] => 50
[117] => 49
[56] => 47
...skipped for brevity...
)
---------------------------------------------------------------------
Array
(
[245] => 21
[222] => 19
[240] => 18
[6] => 18
[252] => 17
[55] => 16
[106] => 15
[201] => 15
[79] => 14
[133] => 14
[56] => 14
[119] => 14
[29] => 14
[117] => 14
[164] => 13
[118] => 13
[157] => 13
[104] => 13
[196] => 13
[241] => 13
...skipped for brevity...
)
I advise you to run it and see for yourself: while distribution in JSON part shows high peaks for often-repeated character, the distribution for gibberish is much more even.
Which is a strong indicator for encrypted data.
So the problem is not with the payload, but with deciphering it.
And it occurred to me that there is just the same common problem when uploading a zip file to FTP. If you happen to use text mode in your FTP client, then line ending characters which may happen in the encrypted data may be irreversibly lost due to conversion. This is most often happens with Windows because it uses different line endings than Unix/Linux.
So my suggestion is that you check the code for downloading the encrypted data and see if a binary mode may be enabled somewhere. For example, if you use fopen, then read mode should be denoted as 'rb' ('b' for binary-safe), and not just 'r'. If you use a different transport, it's up to you to inspect it.
Using opencart 3 and trying to make use of the events but I'm unable to find the identifier.
E.g trying to extend the returns form added an event:
$this->model_setting_event->addEvent('mail_account_return_after', 'catalog/model/account/return/addReturn/after', 'extension/module/return/returnAdd');
Controller:
class ControllerExtensionModuleReturn extends Controller {
public function returnAdd(&$route, &$args, &$output) {
print_r($args);
exit;
$args is missing the main return_id identifier:
Array
(
[0] => Array
(
[firstname] => Foo
[lastname] => Bar
[email] => test#gmail.com
[telephone] => 01234556789
[order_id] => 29
[date_ordered] => 2017-06-29
[product] => Canon EOS 5D
[model] => Product 3
[quantity] => 1
[return_reason_id] => 4
[opened] => 0
[comment] => Test comment
)
)
Tried with $this->db->getLastId() but this returns 0. Tested with other events and appears to be missing the main identifiers.
Where does opencart set what data is passed to the before/after events?
If I'm not mistaken you should be able to access the auto increment return_id in $output, which holds the output of method addReturn(), i.e., $this->db->getLastId();.
As to why calling getLastId() a second time from within your event doesn't work, that's a good question. I would assume there may be some other query happening in between - though by default I don't think there should be. Is it possible there is another trigger running a query before your event gets triggered?
Look in system/engine/loader.php at for the strings before and after. There are methods that do view, controller, configuration and language.
I am currently trying to export a number of products from a custom CMS MYSQL database into a Magento compatible database.
The products include product descriptions which is stored as HTML that was serialised in a "ob_data" array with some other info when they were added through CMS system. Here is an example of one:
Array
(
[id] => 1085
[type] => 9
[url_key] => royal-worcester-mikado-milk-jug
[name] => Royal Worcester Mikado 1/2 Pint Milk Jug
[pattern] => Mikado
[manufacturer] => Royal Worcester
[stock] => 0
[content] => <p>Bone china<br />Holds approx1/2 pint.<br />Excellent condition.</p>
[weight] => 0.75
[price] => 20.00
[image] => /media/dContent/eCommerce/old/165.jpg
)
Using unserialze I can extract this and some other info into an array which can be written to the CSV. However when I write this information to a CSV file with fputcsv I get the following:
1085,9,royal-worcester-mikado-milk-jug,"Royal Worcester Mikado 1/2 Pint Milk Jug",Mikado,"Royal Worcester",0,"<p>Bone china<br />
Holds approx 1/2 pint.<br />
Excellent condition.</p>",0.75,20.00,/media/dContent/eCommerce/old/165.jpg
Essentially the <br/> tags that are in the description are also adding new lines in my CSV breaking its format and making it impossible to import.
Is there anyway that I can stop this happening and format the content so that it can comfortably written into the CSV?
I have the following code:
$this->api = new App_Other_SphinxSearch();
$this->api->SetServer($host, $port);
$this->api->SetConnectTimeout(1);
$this->api->SetArrayResult(true);
$results = $this->api->Query("#(title,content) test", 'members');
echo "<pre>";print_r($results);die;
According to their documentation, a syntax like #(field_1,field_2) query should return docs which match the string query in either field_1 or field_2.
The PHP SDK returns something entirely different:
Array
(
[error] =>
[warning] =>
[status] => 0
[fields] => Array
(
[0] => title
[1] => content
)
[attrs] => Array
(
[created] => 2
[content] => 7
)
[total] => 0
[total_found] => 0
[time] => 0.000
[words] => Array
(
[title] => Array
(
[docs] => 10
[hits] => 34
)
[content] => Array
(
[docs] => 34
[hits] => 139
)
[test] => Array
(
[docs] => 26
[hits] => 34
)
)
)
There is no matches key in the array, however it got some hits. I don't really understand why this is happening, especially because if I try the same query from the command line, everything works correctly.
Any help?
Edit: Querying like this works though: #* test. Not really what I want though, cause that searches in all fields.
[total_found] => 0 says there where no matches.
The words array, just tells you now many documents and how many times that word appears in ANY (and all) fields. (WITHOUT regard to your specific query)
Sphinx caches those word stats, which help it make quick sanity checks on queries. When the query runs it can end up not matching any documents (because only then does it apply the field level filters), even though the individual words are found.
That explains your misinpretation of the results, but not why getting the results you get.
You are entering a Extended Mode query (as evidenced by the link to the sphinx documentation) , but the sphinx API defaults to ALL query mode. Notice also that title and content are in the words array, so are being taken as plain keywords not as syntax.
So you need to include a
$this->api->SetMatchMode(SPH_MATCH_EXTENDED);
btw, #* test, works because the #* are simply ignored in ALL query mode.
I'm using the Nestoria API to retrieve property results.
Everything is working quite well and one can return up to 50 properties using this method.
I would like to show 10 items at a time and allow for the user to paginate through them, but for some reason I'm having difficulty doing this.
The code snippet around the section that controls this is as follows:
$page = isset($_REQUEST["page"]) ? (int)$_REQUEST["page"] : 1;
$page = $page-1;
$pagination = new pagination;
$propertyResults = $pagination->generate($nestoria->decodedData->response->listings, 10);
foreach($propertyResults as $listing) {
//do stuff
}
A snippet of the data array would be:
Array
(
[0] => stdClass Object
(
[auction_date] =>
[property_type] => house
[summary] => Located in North Kingston a two double bedroom Victorian house presented in...
[title] => York Road, Kingston, KT2 - Reception
[updated_in_days] => 6.5
[updated_in_days_formatted] => this week
)
[1] => stdClass Object
(
[auction_date] =>
[property_type] => house
[summary] => Fine home was built about 50 years ago and enjoys one of the best locations...
[title] => Coombe Hill, KT2 - Conservatory
[updated_in_days] => 2.5
[updated_in_days_formatted] => this week
)
....
(sample cut down due to size of array elements)
Now I have been staring at this for way too long now and I've drawn a blank.
This code works correctly except if I try go to any other page other than 1, then the page doesn't finish loading, it just carries on until Firefox says: "The page isn't redirecting properly".
So basically, pagination is able to cut my data array up correctly, but is failing to "paginate" correctly.
Any help?
Turns out the problem with the redirect was actually an .htaccess issue which was using the $_GET["page"] variable and was therefore getting confused, so I renamed all references to the $_GET["page"] to $_GET["_page"] in this app.