admin管理员组文章数量:1130349
I would like to create a Wordpress page that lists temperature and humidity data. The data originates in an encoded .txt file. I'm using the following PHP file to decode the data in the text file. I haven't been successful at creating a functional page in Wordpress using this code.
The .txt file is also reproduced below.
<?php
// publish_payload_in_json.php
// Remote Home Monitor with Hologram Nova
// Publish JSON payload
// Decodes Hologram payload and publishes it in JSON format. JSON data is
// later loaded by the Remote Home Monitor dashboard with JQuery.
//
// Luis Ortiz - luislab
// January 5, 2018
$whFileName = "./payload.txt"; // Home Monitor payload
if ( is_readable($whFileName) ) { // better than file_exists()
$whFileHandle = fopen($whFileName, 'r') or die("1815");
$data = trim(fgets($whFileHandle));
$data = base64_decode($data);
fclose($whFileHandle);
if ( $_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_SERVER['QUERY_STRING']) ) {
header('HTTP/1.1 200 OK');
header('Content-Type: application/json');
echo $data;
}else {
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
}
}
?>
Payload.txt
eyJ0ZW1wZXJhdHVyZSI6IDY3LjQ2MDAwMTM3MzI5MTAyLCAiaHVtaWRpdHkiOiA0OC45MDAwMDE1MjU4Nzg5MDZ9
5x.20x.5x.21x
HologramCloud ()
webhookkeyxxxxxx
I would like to create a Wordpress page that lists temperature and humidity data. The data originates in an encoded .txt file. I'm using the following PHP file to decode the data in the text file. I haven't been successful at creating a functional page in Wordpress using this code.
The .txt file is also reproduced below.
<?php
// publish_payload_in_json.php
// Remote Home Monitor with Hologram Nova
// Publish JSON payload
// Decodes Hologram payload and publishes it in JSON format. JSON data is
// later loaded by the Remote Home Monitor dashboard with JQuery.
//
// Luis Ortiz - luislab
// January 5, 2018
$whFileName = "./payload.txt"; // Home Monitor payload
if ( is_readable($whFileName) ) { // better than file_exists()
$whFileHandle = fopen($whFileName, 'r') or die("1815");
$data = trim(fgets($whFileHandle));
$data = base64_decode($data);
fclose($whFileHandle);
if ( $_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_SERVER['QUERY_STRING']) ) {
header('HTTP/1.1 200 OK');
header('Content-Type: application/json');
echo $data;
}else {
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
}
}
?>
Payload.txt
eyJ0ZW1wZXJhdHVyZSI6IDY3LjQ2MDAwMTM3MzI5MTAyLCAiaHVtaWRpdHkiOiA0OC45MDAwMDE1MjU4Nzg5MDZ9
5x.20x.5x.21x
HologramCloud ()
webhookkeyxxxxxx
本文标签: phpNeed help to create Wordpress page that decodes a text file and publishes it in JSON format
版权声明:本文标题:php - Need help to create Wordpress page that decodes a text file and publishes it in JSON format 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749046865a2307982.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论