Ad Widget

Collapse

Trying to get timestamps in json call in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • waardd
    Member
    • Aug 2014
    • 82

    #1

    Trying to get timestamps in json call in php

    Im trying to parse a variable into a json call but the values are not transfered... can anybody point me in the right direction?

    Code:
    date_default_timezone_set("Europe/Amsterdam");
    echo "Europe/Amsterdam:".time();
    $fromtime = time();
    echo "<br>";
    echo "From time: ". $fromtime;
    echo "<br>";
    $totime= time() - (7 * 24 * 60 * 60 );
    echo "To time: ". $totime;
    echo "<br>";
    
    function zabbix_get_events($uri, $authtoken) {
    /*
    "params": {
        "time_from": "1284910040",
        "time_till": "1284991200",
        "output": "extend",
        "sortfield": "clock",
        "sortorder": "desc",
        "limit": 10
    */
            $data = array(
                    'jsonrpc' => "2.0",
                    'method' => "event.get",
                    'params' => array(
                            'time_from' => "".$fromtime,
                            'time_till' => "".$totime,
                            'output' => "extend",
                            'sortfield' => "clock",
                            'sortorder' => "desc",
                            'limit'=> 10
                    ),
                    'id' => "2",
                    'auth' => $authtoken
            );
            $response = json_request($uri, $data);
            return $response['result'];
    }
    translates to:
    Code:
    JSON Request:
    {"jsonrpc":"2.0","method":"event.get","params":{"time_from":"","time_till":"","output":"extend","sortfield":"clock","sortorder":"desc","limit":10},"id":"2","auth":"8be687b6aff4f99e14c906dbe01755b4"}
  • zabbixx
    Member
    • Jul 2012
    • 71

    #2
    Hello, what is the name of this variable that you cant pas to the data ?
    maybe you try to putput this var in the php... is it existing is it empty ?

    use global to acces variables that are global defined (not in the function)

    Code:
    <?php
    $a = 1;
    $b = 2;
    
    function Summe()
    {
        global $a, $b;
    
        $b = $a + $b;
    } 
    
    Summe();
    echo $b;
    ?>
    Last edited by zabbixx; 16-06-2015, 00:44.

    Comment

    • waardd
      Member
      • Aug 2014
      • 82

      #3
      I figured it out... i should parse it in the function call

      Tnx

      Comment

      Working...