PHP code example of palanik / corsslim

1. Go to this page and download the library: Download palanik/corsslim library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

palanik / corsslim example snippets



 = new \Slim\Slim();

$app->add(new \CorsSlim\CorsSlim());


\Slim\Slim::registerAutoLoader();

$app = new \Slim\Slim();


$corsOptions = array(
    "origin" => "*",
    "exposeHeaders" => array("X-My-Custom-Header", "X-Another-Custom-Header"),
    "maxAge" => 1728000,
    "allowCredentials" => True,
    "allowMethods" => array("POST, GET"),
    "allowHeaders" => array("X-PINGOTHER")
    );
$cors = new \CorsSlim\CorsSlim($corsOptions);

$corsOptions = array(
    "origin" => array('http://one.allowed-origin.com', 'http://two.allowed-origin.com'),
    "exposeHeaders" => array("X-My-Custom-Header", "X-Another-Custom-Header"),
    "maxAge" => 1728000,
    "allowCredentials" => True,
    "allowMethods" => array("POST, GET"),
    "allowHeaders" => array("X-PINGOTHER")
    );
$cors = new \CorsSlim\CorsSlim($corsOptions);


= new \Slim\Slim();

$app->get('/item/:id', 
          \CorsSlim\CorsSlim::routeMiddleware(), 
          function ($name) use ($app) {
            ...
          }
        );


= new \Slim\Slim();

$corsOptions = array("origin" => "*");
$app->get('/item/:id', 
          \CorsSlim\CorsSlim::routeMiddleware($corsOptions), 
          function ($name) use ($app) {
            ...
          }
        );



= new \Slim\Slim();

$app->options('/item', 
          \CorsSlim\CorsSlim::routeMiddleware(), 
          function ($name) use ($app) {}
        );
$app->post('/item', 
          \CorsSlim\CorsSlim::routeMiddleware(), 
          function ($name) use ($app) {
            ...
          }
        );