Category Archives: api

DateTimeZone Errors [on hold]

When I'm Trying to enter website , blank(white) page opens. I don't know what wrong with my php, I took something from apache errors.

Apache2/Errors log

 PHP Warning:  session_start(): open(/home/frontend_sessions/sess_5gui667au5hduqvt927a92t7r1, O_RDWR) failed: No such file or directory (2) in /var/www/html/frontend/lib/common.php on line 52
 PHP Notice:  Undefined property: object::$default_timezone in /var/www/html/frontend/lib/common.php on line 92
 PHP Notice:  date_default_timezone_set(): Timezone ID '' is invalid in /var/www/html/frontend/lib/common.php on line 92
 PHP Notice:  Undefined property: object::$default_timezone in /var/www/html/frontend/lib/common.php on line 93
PHP Fatal error:  Uncaught Exception: DateTimeZone::__construct(): Unknown or bad timezone () in /var/www/html/frontend/lib/common.php:93\nStack trace:\n#0 /var/www/html/frontend/lib/common.php(93): DateTimeZone->__construct('')\n#1 /var/www/html/frontend/htdocs/index.php(4): include('/var/www/html/f...')\n#2 {main}\n  thrown in /var/www/html/frontend/lib/common.php on line 93
PHP Warning:  Unknown: open(/home/frontend_sessions/sess_5gui667au5hduqvt927a92t7r1, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/home/frontend_sessions) in Unknown on line 0

Line 52

$sessionValue = session_start();

LİNE 92-93

date_default_timezone_set($CFG->default_timezone);
$dtz = new DateTimeZone($CFG->default_timezone);

frontend/cfg

 <?php
    class object {}
    $CFG = new object();
    if ($_SERVER['SERVER_NAME'] == 'localhost') {
        $base_url = "http://xxxxx.com/bit_live/";
        $CFG->api_url = $base_url.'api/htdocs/api.php';
        $CFG->auth_login_url = $base_url.'auth/htdocs/login.php';
        $CFG->auth_verify_token_url = $base_url.'auth/htdocs/verify_token.php';
    } else {
        $base_url = "http://xxxx.com/bit_live/";
    $CFG->api_url = 'https://api.xxxx.com/api.php';
    $CFG->auth_login_url = 'https://auth.xxx.com/login.php';
    $CFG->auth_verify_token_url = 'https://auth.xxx.com/verify_token.php';
    }


    ?>

.Api/cfg maybe mistake is here

   <?php
    class object {}
    $CFG = new object();
    if ($_SERVER['SERVER_NAME'] == 'localhost') {
        $CFG->dbhost = "localhost";
        $CFG->dbname = "xxx";
        $CFG->dbuser = "root";
        $CFG->dbpass = "xxx";
    } else {
        $CFG->dbhost = "localhost";
    $CFG->dbname = "xxx";
    $CFG->dbuser = "root";
    $CFG->dbpass = "xxx";
    }


    ?>

I have like that errors about timezone I don't know what should l do If you can help me I will be happy :)

Apache Ignite Locks for synchronizing arbitrary computation across the grid

I have a simple question for which I can't really find a definitive answer in the Apache Ignite docs.

I see that there is an API in Apache Ignite to create a explicit lock. I understand that these locks are used for writing cache entries and this is done implicitly.

However, can I (should I) be able to explicitly create a Lock in my grid to synchronizing computation some arbitrary code. Here's what I'm thinking of doing:

  1. Request comes into my API.
  2. I try to enter a lock on my Ignite cache
  3. If I can enter the lock I do some calculation (which should only be done on one of my API instances at any given time)
  4. If I can't enter the lock, I return 409 error code (duplicate request)
  5. I exit the lock

Are there potential caveats to doing this? Should I watch out for potential pitfalls?

URL Rewrite For API – Check Request From URL

I have two questions
Q1 : how can i rewrite this url with htaccess ?

localhost/?api=ASdhUAe2Q48
To => localhost/ASdhUAe2Q48/

Q2 : how can i check the request for get data are from wich url ?
it's meant for example :
i have this website : www.me.com
and your website is : www.you.com
now when you want to get data from my website with cURL or file_get_content or etc. i should know that this url is avalable or not (in mysql)
i have this mysql table for API :

users_api => { api_id , users_id , api_key , api_name , api_url }


Thanks and sorry for my poor english.


Edit : I found awnser #1 :

RewriteRule ([^/]*)/$ /index.php?api=$1[L]

Yii2 Setting unknown property: yii\filters\auth\HttpBearerAuth::formats

I am creating apis in YII2 each and every request is working well but in PUT request I am getting below error

Unknown Property – yii\base\UnknownPropertyException

Setting unknown property: yii\filters\auth\HttpBearerAuth::formats

This is my stack trace

  1. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Object.php at line 161 152153154155156157158159160161162163164165166167168169170
    */ public function __set($name, $value) { $setter = 'set' . $name; if (method_exists($this, $setter)) { $this->$setter($value); } elseif (method_exists($this, 'get' . $name)) { throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name); } else { throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name); } }

    /**

    • Checks if a property is set, i.e. defined and not null. *
    • Do not call this method directly as it is a PHP magic method that
    • will be implicitly called when executing isset($object->property). *
  2. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\BaseYii.php at line 525 – yii\base\Object::__set('formats', ['application/json' => 'json'])
  3. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Object.php at line 105 – yii\BaseYii::configure(yii\filters\auth\HttpBearerAuth, ['only' => ['index', 'view', 'create', 'update', ...], 'formats' => ['application/json' => 'json']])
  4. yii\base\Object::__construct(['only' => ['index', 'view', 'create', 'update', ...], 'formats' => ['application/json' => 'json']])
  5. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\di\Container.php at line 381 – ReflectionClass::newInstanceArgs([['only' => ['index', 'view', 'create', 'update', ...], 'formats' => ['application/json' => 'json']]])
  6. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\di\Container.php at line 156 – yii\di\Container::build('yii\filters\auth\HttpBearerAuth', [], ['only' => ['index', 'view', 'create', 'update', ...], 'formats' => ['application/json' => 'json']])
  7. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\BaseYii.php at line 344 – yii\di\Container::get('yii\filters\auth\HttpBearerAuth', [], ['only' => ['index', 'view', 'create', 'update', ...], 'formats' => ['application/json' => 'json']])
  8. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Component.php at line 667 – yii\BaseYii::createObject(['class' => 'yii\filters\auth\HttpBearerAuth', 'only' => ['index', 'view', 'create', 'update', ...], 'formats' => ['application/json' => 'json']])
  9. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Component.php at line 651 – yii\base\Component::attachBehaviorInternal(0, ['class' => 'yii\filters\auth\HttpBearerAuth', 'only' => ['index', 'view', 'create', 'update', ...], 'formats' => ['application/json' => 'json']])
  10. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Component.php at line 533 – yii\base\Component::ensureBehaviors()
  11. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Controller.php at line 272 – yii\base\Component::trigger('beforeAction', yii\base\ActionEvent)
  12. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\web\Controller.php at line 164 – yii\base\Controller::beforeAction(yii\rest\UpdateAction)
  13. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Controller.php at line 154 – yii\web\Controller::beforeAction(yii\rest\UpdateAction)
  14. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Module.php at line 523 – yii\base\Controller::runAction('update', ['id' => '1'])
  15. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\web\Application.php at line 102 – yii\base\Module::runAction('products/update', ['id' => '1'])
  16. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Application.php at line 380 – yii\web\Application::handleRequest(yii\web\Request)
  17. in D:\xampp\htdocs\connect\index.php at line 12 – yii\base\Application::run() 6789101112 require(DIR . '/vendor/autoload.php'); require(DIR . '/vendor/yiisoft/yii2/Yii.php'); $config = require(DIR . '/config/web.php'); (new yii\web\Application($config))->run(); $_GET = [ 'id' => '1', ]; Yii Framework 2017-02-23, 09:31:51

Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.28 Yii Framework/2.0.11.2

Behaviors in controller is

  public function behaviors() {
        return [
            [
                'class' => HttpBearerAuth::className(),
                'only' => ['index', 'view', 'create', 'update', 'search'],
                'formats' => ['application/json' => Response::FORMAT_JSON,],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'index' => ['get'],
                    'view' => ['get'],
                    'create' => ['post'],
                    'update' => ['PUT'],
                    'delete' => ['delete'],
                    'deleteall' => ['post'],
                    'search' => ['get']
                ],
            ]
        ];
    }

I am testing it with postman and passing Authorization in each api.

This is my header

enter image description here

What could be the issue?

Creating a Rest API in PHP causing a redirect error

I'm trying to work out to create a proper RESTful API in PHP. I've been following some steps from http://coreymaynard.com/blog/creating-a-restful-api-with-php/ and to me it looks like I've done everything exactly the same except when I try and go to http://localhost/api/v1/example I get an internal server error.

In the apache error log I am seeing the following:

[Sat Feb 18 19:30:10.594193 2017] [core:error] [pid 10272:tid 1144] [client ::1:58203] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Sat Feb 18 19:30:10.594193 2017] [core:debug] [pid 10272:tid 1144] core.c(3747): [client ::1:58203] AH00121: r->uri = /api/v1/api.php
[Sat Feb 18 19:30:10.594193 2017] [core:debug] [pid 10272:tid 1144] core.c(3753): [client ::1:58203] AH00122: redirected from r->uri = /api/v1/api.php
[Sat Feb 18 19:30:10.594193 2017] [core:debug] [pid 10272:tid 1144] core.c(3753): [client ::1:58203] AH00122: redirected from r->uri = /api/v1/api.php
[Sat Feb 18 19:30:10.594193 2017] [core:debug] [pid 10272:tid 1144] core.c(3753): [client ::1:58203] AH00122: redirected from r->uri = /api/v1/api.php
[Sat Feb 18 19:30:10.594193 2017] [core:debug] [pid 10272:tid 1144] core.c(3753): [client ::1:58203] AH00122: redirected from r->uri = /api/v1/api.php
[Sat Feb 18 19:30:10.594193 2017] [core:debug] [pid 10272:tid 1144] core.c(3753): [client ::1:58203] AH00122: redirected from r->uri = /api/v1/api.php
[Sat Feb 18 19:30:10.594193 2017] [core:debug] [pid 10272:tid 1144] core.c(3753): [client ::1:58203] AH00122: redirected from r->uri = /api/v1/api.php
[Sat Feb 18 19:30:10.594193 2017] [core:debug] [pid 10272:tid 1144] core.c(3753): [client ::1:58203] AH00122: redirected from r->uri = /api/v1/api.php
[Sat Feb 18 19:30:10.594193 2017] [core:debug] [pid 10272:tid 1144] core.c(3753): [client ::1:58203] AH00122: redirected from r->uri = /api/v1/api.php
[Sat Feb 18 19:30:10.594193 2017] [core:debug] [pid 10272:tid 1144] core.c(3753): [client ::1:58203] AH00122: redirected from r->uri = /api/v1/api.php
[Sat Feb 18 19:30:10.594193 2017] [core:debug] [pid 10272:tid 1144] core.c(3753): [client ::1:58203] AH00122: redirected from r->uri = /api/v1/example

My BaseAPI class (what they call API in the example) is below:

abstract class API
{
    protected $method = '';
    protected $endpoint = '';
    protected $verb = '';
    protected $args = Array();

    public function __construct($request)
    {
        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Method: *");
        header("Content-Type: application/json");

        $this->args = explode('/', rtrim($request, '/'));
        $this->endpoint = array_shift($this->args);
        if (array_key_exists(0, $this->args) && !is_numeric($this->args[0]))
        {
            $this->verb = array_shift($this->args);
        }

        $this->method = $_SERVER["REQUEST_METHOD"];
        if ($this->method === "POST" && array_key_exists('HTTP_X_HTTP_METHOD', $_SERVER))
        {
            if ($_SERVER['HTTP_X_HTTP_METHOD'] === "DELETE")
            {
                $this->method = "DELETE";
            }
            else if ($_SERVER["HTTP_X_HTTP_METHOD"] === "PUT")
            {
                $this->method = "PUT";
            }
            else
            {
                throw new Exception("Unexpected header");
            }
        }

        switch ($this->method)
        {
            case 'DELETE':
            case 'POST':
                $this->request = $this->cleanInputs($_POST);
                break;
            case 'GET':
                $this->request = $this->cleanInputs($_GET);
                break;
            case 'PUT':
                $this->request = $this->clearInputs($_GET);
                $this->file = file_get_contents("php://input");
                break;
            default:
                $this->response('Invalid Method', 405);
                break;
        }
    }

    public function processAPI()
    {
        if (method_exists($this, $this->endpoint))
        {
            return $this->response($this->{$this->endpoint}($this->args));
        }
        return $this->response("No Endpoint: $this->endpoint", 404);
    }

    private function response($data, $status = 200)
    {
        header("HTTP/1.1 " . $status . " " . $this->requestStatus($status));
        return json_encode($data);
    }

    private function cleanInputs($data)
    {
        $clean_input = Array();
        if (is_array($data))
        {
            foreach ($data as $key => $value)
            {
                $clean_input[$key] = $this->cleanInputs($value);
            }
        }
        else
        {
            $clean_input = htmlspecialchars($data);
        }
        return $clean_input;
    }

    private function requestStatus($code)
    {
        $status = array(
            200 => 'OK',
            404 => 'Not Found',
            405 => 'Method Not Allowed',
            500 => 'Internal Server Error'
        );
        return ($status[$code])?$status[$code]:$status[500];
    }
}

The MyAPI file is as follows:

require_once 'BaseApi.php';

class MyAPI extends API
{
    public function __construct($request)
    {
        parent::__construct($request);
    }

    protected function example()
    {
        if ($this->method === "GET")
        {
            return "Hello to my RESTful API";
        }
        else
        {
            return "Only accepts GET requests";
        }
    }
}

My api.php is as follows:

require_once 'MyAPI.php';

try
{
    $api = new MyAPI($_REQUEST['request']);
    echo $api->processAPI();
}
catch (Exception $ex)
{
    echo $ex->getMessage();
}

My .htaccess file is as follows:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule api/v1/(.*)$ api/v1/api.php?request=$1 [QSA,NC,L]
</IfModule>

It looks like to me everything is exactly the same as in that article, if it makes any difference I'm using Wamp server running on Windows 10.

Thanks for any help you can provide.

bug in apache openmeetings api in getExternal for RoomService

i am using apache OpenMeetings api and when i try to getExternal room by its argument i get this error message: http://webservice.openmeetings.apache.org/}org.apache.openmeetings.webservice.RoomWebService#{http://webservice.openmeetings.apache.org/}getExternal has thrown exception, unwinding now org.apache.cxf.interceptor.Fault: An error occurred while parsing the query filter "select r from Room as r where r.externalId = :externalId AND c.externalType = :externalType AND r.type = :type AND c.deleted = false". Error message: Attempt to query and when i track the error in apache OpenMeeting project i founded this Bug in the package org.apache.openmeetings.db.entity.room;:

    @NamedQuery(name = "getRoomByExternalId", query = "select r from Room as r "
        + "where r.externalId = :externalId AND c.externalType = :externalType "
        + "AND r.type = :type AND c.deleted = false"),

how can use this api or fix it

thanks...

Limit the number of a client requests sent to a server

I have an API with PHP and nusoap and it is launched on a server with Apache web server. Different remote clients send requests to my API functions and get response. I want to restrict clients requests to a specific function in this way:

There is a limitation for requests which can be sent by a client in every second and this limitation is stored in mysql database. Each client must be able to send requests up to its limitation. For example if the maximum requests defined for a client is 300, it is not allowed to send more than 300 requests in second.

How can I implement this rule with PHP or Apache?

how to create new user in apache openmeetings api via ajax?

i'm using apache api open meetings and i use its function and its has been working in login but when i try to add new user i have http response error 500 i try this but it does n't work can any one help me:

                <!DOCTYPE html>
            <html>
            <head>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

            <script>

             function create_user() {

                         $.ajax({
                          method: "POST",
                          url: "http://localhost:5080/openmeetings/services/user",

                          data: {sid : "2575fb6f-c030-4ef4-b9c5-0c6bcb9b18f3",
                                userDTO:JSON.stringify( { address :{
                                        additionalname:"mr"
                                        ,comment:"k"
                                        ,country:"sy"
                                        ,deleted:false
                                        ,email:"[email protected]"
                                        ,fax:"111"
                                        ,id:222
                                        ,inserted:"2014-02-14T08:00Z"
                                        ,phone:"1111"
                                        ,street:"sss"
                                        ,town:"sss"
                                        ,updated:"2014-02-14T08:00Z"
                                        ,zip:"qq"
                                            }
                                    ,externalId:"1"
                                    ,externalType:"myCMS"
                                    ,firstname:"asasas"
                                    ,id:1
                                    ,languageId:55
                                    ,lastname:"zxczxc"
                                    ,login:"asasas"
                                    ,password:"asasas"
                                    ,rights:null
                                    ,timeZoneId:"sa"
                                    ,type:{type:"user"}     
                                    }),
                                confirm: false },

                          dataType: "json",
                          success: function(data){                      
                            $("#res").html(data["id"]);     
                          }
                        });                             
             }

            $(document).ready(function(){
                $("button").click(function(){
                    create_user();
                });
            });
            </script>
            </head>
            <body>
            <button>Get JSON data</button>
            <div id="res"></div>
            </body>
            </html>
            </code>