您可以使用Define
save on define.php
include 以便下次在其他项目上使用 这是PROTOCOL
DOMAIN
PORT
SITE_ROOT
ANDSITE PATH
**
* domain
* ex: localhost, maskphp.com, demo.maskphp.com,...
*/
define('DOMAIN', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']);
/**
* protocol
* ex: http, https,...
*/
define('PROTOCOL', isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] === 1)
|| isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ? 'https' : 'http');
/**
* port
* ex: 80, 8080,...
*/
define('PORT', $_SERVER['SERVER_PORT']);
/**
* site path
* ex: http://localhost/maskphp/ -> /maskphp/
*/
define('SITE_PATH', preg_replace('/index.php$/i', '', $_SERVER['PHP_SELF']));
/**
* site root
* ex: http://maskgroup.com, http://localhost/maskphp/,...
*/
define('SITE_ROOT', PROTOCOL . '://' . DOMAIN . (PORT === '80' ? '' : ':' . PORT) . SITE_PATH);
您可以调试以查看结果