$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - Need help to create Wordpress page that decodes a text file and publishes it in JSON format|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - Need help to create Wordpress page that decodes a text file and publishes it in JSON format

matteradmin9PV0评论

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
Post a comment

comment list (0)

  1. No comments so far