index.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. ini_set('pcre.backtrack_limit', 999999999);
  3. setlocale(LC_ALL, 'zh_CN.UTF-8');
  4. defined('TIMESTAMP') or define('TIMESTAMP',time());//start time of request
  5. defined('SYS_START_TIME') or define('SYS_START_TIME',microtime());//start time of request
  6. define('IN_KIIVO', true);//make the file be the only import of the app
  7. //KIIVOKMS框架目录,如:D:\phpStudy\PHPTutorial\WWW\kiivokms\
  8. defined('BASE_PATH') or define('BASE_PATH', dirname(dirname(__FILE__).DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR);
  9. //应用目录,如:D:\phpStudy\PHPTutorial\WWW\kiivokms\web\
  10. defined('APP_PATH') or define('APP_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
  11. $config = require __DIR__ . '/../config/config.php';
  12. include_once __DIR__ . '/../common/functions/global.php';
  13. include_once __DIR__ . '/../common/functions/dir.php';
  14. include_once __DIR__ . '/../common/functions/cus.php';
  15. defined('MYIP') or define('MYIP',ip());
  16. $domain = require_config('domain.php');
  17. defined('COOKIE_DOMAIN') or define('COOKIE_DOMAIN', $domain['cookie_domain']);//定义cookie全局域
  18. define('WAP_URL', $domain['wap_url']);//WAP站域名
  19. define('WEB_URL', $domain['web_url']);//PC站域名
  20. define('API_URL', $domain['api_url']);//接口域名
  21. define('UPLOAD_DOMAIN', $domain['upload_domain']);//附件域名
  22. define('CORS_DOMAIN', $domain['cors_origin']);//跨域域名
  23. require __DIR__ . '/../vendor/autoload.php';
  24. require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
  25. //主机协议
  26. define('SITE_PROTOCOL', isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://');
  27. //当前访问的主机名(格式:www.xxx.cn)
  28. define('SITE_URL', (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''));
  29. /*****************判断是否手机端***********************/
  30. if(strpos(WAP_URL,SITE_PROTOCOL.SITE_URL)!==false||check_mobile())
  31. {
  32. defined('IN_WAP') or define('IN_WAP',TRUE);
  33. if(check_baiduapp())
  34. {
  35. defined('REQUEST_FROM') or define('REQUEST_FROM',3);
  36. }
  37. else if(check_wxapp()){
  38. defined('REQUEST_FROM') or define('REQUEST_FROM',4);
  39. }
  40. else if(check_micromsg())
  41. {
  42. defined('REQUEST_FROM') or define('REQUEST_FROM',5);
  43. }
  44. else
  45. {
  46. defined('REQUEST_FROM') or define('REQUEST_FROM',2);
  47. }
  48. defined('APP_URL') or define('APP_URL',WAP_URL);
  49. }
  50. else
  51. {
  52. defined('IN_WAP') or define('IN_WAP',FALSE);
  53. defined('REQUEST_FROM') or define('REQUEST_FROM',1);
  54. defined('APP_URL') or define('APP_URL',WEB_URL);
  55. }
  56. defined("DEVICE_TYPE") or define("DEVICE_TYPE",get_device_type());
  57. $config = array_merge_recursive(require_config('api.php'), $config);
  58. $config['params']['cors_origin'] = $domain['cors_origin'];
  59. $params = $config['params'];
  60. /********************二次定义params结束*****************************************/
  61. defined('UPLOAD_PATH') or define('UPLOAD_PATH',$config['params']['uploadPath']);
  62. defined('THUMB_PATH') or define('THUMB_PATH',$config['params']['thumbPath']);
  63. defined('UPLOAD_URL') or define('UPLOAD_URL',$config['params']['uploadUrl']);
  64. defined('HTML_PATH') or define('HTML_PATH',$config['params']['htmlPath']);
  65. defined('CACHE_PATH') or define('CACHE_PATH',$config['params']['cachePath']);
  66. //定义网页编码
  67. defined('CHARSET') or define('CHARSET',$config['params']['charSet']);
  68. //定义时区
  69. defined('TIME_ZONE') or define('TIME_ZONE',$config['params']['timeZone']);
  70. //加密因子
  71. defined('AUTH_KEY') or define('AUTH_KEY',$config['params']['authKey']);
  72. //判断来源合法性
  73. $reurl = $_SERVER["HTTP_REFERER"]; //获取完整的来路URL
  74. $str = explode("//",$reurl); //去掉http://
  75. $strdomain = explode("/",$str[1]); // 以“/”分开成数组
  76. $redomain = $str[0].'//'.trim($strdomain[0],"/");//取第一个“/”以前的字符
  77. if(in_array($redomain,$domain['cors_origin']))header("Access-Control-Allow-Origin: *");
  78. ob_clean();
  79. (new yii\web\Application($config))->run();