PHP code example of ddvphp / ddv-cors

1. Go to this page and download the library: Download ddvphp/ddv-cors 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/ */

    

ddvphp / ddv-cors example snippets



$res = \DdvPhp\DdvCors::run(array(// 来源
  'origin'=>array(
      'http://127.0.0.1',
      'http://127.0.0.1:*',
      'http://10.*.*.*',
      'http://10.*.*.*:*',
      'http://www.ddvjs.net',
  ),
  // 授权请求
  'method'=>array(
      'GET',
      'POST',
      'PUT',
      'HEAD',
      'DELETE'
  ),
  // 授权请求头
  'allowHeader'=>array(
      'accept',
      'authorization',
      'content-md5',
      'content-type',
      'x-requested-with',
      'x_requested_with',
      'cookie',
      'origin',
      'x-ddv-*'

  ),
  // 授权响应头读取
  'exposeHeader'=>array(
      'set-cookie',
      'x-ddv-request-id',
      'x-ddv-session-sign'
  ),
  // 缓存时间
  'control'=>7200
));




class Cors extends \DdvPhp\DdvCors
{
  // 重新头输出方式
  public static function header($header)
  {
    @header($header);
  }
}

$res = Cors::run($config);