S
sunilsmartwiz

  • Jun 22, 2020
  • Joined Mar 1, 2020
  • Hi @ all!
    I was looking for a way to send responses with own content and own status code and found that PhpMaker is using \Slim\Http. Great thing :-)
    Unfortunately I am unable to access the response object that will be returned to the Slim framework as I did not find a way to access this object. As far as I code read the code you are trying to give access on the response object by providing the global var $Response. Unfortunately you are assigning a reference to the glabl var placeholder, which does not change the global var itself. Please see example code below. How can I achieve to access this object? Alternatively: How can I reply json data with my own http statuscode?

    Thx!
    Patrick

    // code snippet from api/index.php
    
    //// Set up request/response objects
    //global $Request, $Response, $RequestSecurity, $API_ACTIONS;
    //$Request = $request;
    //$Response = &$response; // <<<<<<<<<<< asssigning reference
    //$RequestSecurity = $Api->decodeJWT($request->getHeader($Api->AuthHeader));
    //
    //// Handle custom actions first
    //if (in_array($action, array_keys($API_ACTIONS))) {
    // $func = $API_ACTIONS[$action];
    // if (is_callable($func))
    // call_user_func($func, $request, $response);
    // return $response; // <<<<<<<<<<<<<<<<<< returning local object not accessible to me
    
    
    // abstract example:
    
    namespace {
    
    $globalVar = 'global';
    }
    
    namespace myNamespace {
    
    function myMethod() {
    $localVar = 'local';
    global $globalVar;
    
    echo "localVar = [$localVar]\n";
    echo "globalVar = [$globalVar]\n";
    echo "GLOBALS = [" . $GLOBALS['globalVar'] . "]\n\n";
    
    $globalVar = &$localVar;
    
    echo "localVar = [$localVar]\n";
    echo "globalVar = [$globalVar]\n";
    echo "GLOBALS = [" . $GLOBALS['globalVar'] . "]\n";
    }
    
    myMethod();
    }
    
    // output:
    // localVar = [local]
    // globalVar = [global]
    // GLOBALS = [global]
    //
    // localVar = [local]
    // globalVar = [local]
    // GLOBALS = [global]
    I am using this on server
    
    • can any help me out on the cron page=processqueue&secret=XXXX using the following code :cry:
      I try this it does not work 01:

      <?php
      function process_queue() {
      //variables
      $url = "http://domainname.com/lists/admin/?page=processqueue&secret=hereTheCode";
      
      //open connection
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      $result = curl_exec($ch);
      
      //clean up
      curl_close($ch);
      
      return $result;
      }
      $result = process_queue();
      
      ///////
      
      ?>

      I get this error in the email:

      <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
      <html><head>
      <title>500 Internal Server Error</title>
      </head><body>
      <h1>Internal Server Error</h1>
      <p>The server encountered an internal error or
      misconfiguration and was unable to complete
      your request.</p>
      <p>Please contact the server administrator,
      emailname@emailaddres.com and inform them of the time the error occurred,
      and anything you might have done that may have
      caused the error.</p>
      <p>More information about this error may be available
      in the server error log.</p>
      <p>Additionally, a 404 Not Found
      error was encountered while trying to use an ErrorDocument to handle the request.</p>
      </body></html>

      This code is at below given link where i am getting problem. I will share cpanel details if anyone can solve the problem.

      [Mod: fixed code quoting; removed bogus link to really sad site where you buy bots to follow you on Instagram]