$_SERVER里的东西 给你个joomla的代码片断if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) { $https = 's://'; } else { $https = '://'; } /* * Since we are assigning the URI from the server variables, we first need * to determine if we are running on apache or IIS. If PHP_SELF and REQUEST_URI * are present, we will assume we are running on apache. */ if (!empty ($_SERVER['PHP_SELF']) && !empty ($_SERVER['REQUEST_URI'])) { /* * To build the entire URI we need to prepend the protocol, and the http host * to the URI string. */ $theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; /* * Since we do not have REQUEST_URI to work with, we will assume we are * running on IIS and will therefore need to work some magic with the SCRIPT_NAME and * QUERY_STRING environment variables. */ } else { // IIS uses the SCRIPT_NAME variable instead of a REQUEST_URI variable... thanks, MS $theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']; // If the query string exists append it to the URI string if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) { $theURI .= '?' . $_SERVER['QUERY_STRING']; } } // Now we need to clean what we got since we can't trust the server var $theURI = urldecode($theURI); $theURI = str_replace('"', '"',$theURI); $theURI = str_replace('<', '<',$theURI); $theURI = str_replace('>', '>',$theURI); $theURI = preg_replace('/eval\((.*)\)/', '', $theURI); $theURI = preg_replace('/[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']/', '""', $theURI);
realpath是处理路径,而不是得到路径的方法
SERVER_FILENAME得到的是绝对路径,但那不是我想要的我想得到的是如http://localhost/test/下文件index.php
不管是它上层,或是下层目录,在调用这个文件的时候,其中的路径是不变的(img.src)都可以正确显示
像这种:E://wwwroot/test/ img是不支持的,显示不了
给你个joomla的代码片断if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) {
$https = 's://';
} else {
$https = '://';
} /*
* Since we are assigning the URI from the server variables, we first need
* to determine if we are running on apache or IIS. If PHP_SELF and REQUEST_URI
* are present, we will assume we are running on apache.
*/
if (!empty ($_SERVER['PHP_SELF']) && !empty ($_SERVER['REQUEST_URI'])) { /*
* To build the entire URI we need to prepend the protocol, and the http host
* to the URI string.
*/
$theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; /*
* Since we do not have REQUEST_URI to work with, we will assume we are
* running on IIS and will therefore need to work some magic with the SCRIPT_NAME and
* QUERY_STRING environment variables.
*/
}
else
{
// IIS uses the SCRIPT_NAME variable instead of a REQUEST_URI variable... thanks, MS
$theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']; // If the query string exists append it to the URI string
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
$theURI .= '?' . $_SERVER['QUERY_STRING'];
}
} // Now we need to clean what we got since we can't trust the server var
$theURI = urldecode($theURI);
$theURI = str_replace('"', '"',$theURI);
$theURI = str_replace('<', '<',$theURI);
$theURI = str_replace('>', '>',$theURI);
$theURI = preg_replace('/eval\((.*)\)/', '', $theURI);
$theURI = preg_replace('/[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']/', '""', $theURI);
echo $theURI;
给你一些参考的
realpath得到物理绝对路径
$_SERVER['DOCUMENT_ROOT'] 可得到如 http://example.org/ 域名跟目录的物理路径,可同时配合 realpath 得到绝对物理路径可通过以上两者计算得到不少东西了另外如果想根据域名跟目录调用,链接或者图片地址可以使用 /images/xx.png /js/script.js 这样的以 / 开头的路径即表示从域名跟目录开始定位,不论你当前访问的是在哪里如 http://example.org/sub1/1.html 调用了 1.png 则实际为 http://example.org/sub1/1.png
若调用 /1.png 则实际为 http://example.org/1.png