绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
php学习笔记
2014-05-27 00:00:00

1、$_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest' 判断请求是不是ajax请求

2、获得当前服务器的主机名:

function extract_current_hostname() {
	global $config;    //全局配置
	// Get hostname
	$host = (! empty ( $_SERVER ['HTTP_HOST'] )) ? $_SERVER ['HTTP_HOST'] : ((! empty ( $_SERVER ['SERVER_NAME'] )) ? $_SERVER ['SERVER_NAME'] : getenv ( 'SERVER_NAME' ));
		
	// Should be a string and lowered
	$host = ( string ) strtolower ( $host );
		
	// If host is equal the cookie domain or the server name (if config is set), then we assume it is valid
	if ((isset ( $config ['cookie_domain'] ) && $host === $config ['cookie_domain']) || (isset ( $config ['server_name'] ) && $host === $config ['server_name'])) {
		return $host;
	}
		
	// Is the host actually a IP? If so, we use the IP... (IPv4)
	if (long2ip ( ip2long ( $host ) ) === $host) {
		return $host;
	}
		
	// Now return the hostname (this also removes any port definition). The http:// is prepended to construct a valid URL, hosts never have a scheme assigned
	$host = @parse_url ( 'http://' . $host );
	$host = (! empty ( $host ['host'] )) ? $host ['host'] : '';
		
	// Remove any portions not removed by parse_url (#)
	$host = str_replace ( '#', '', $host );
		
	// If, by any means, the host is now empty, we will use a "best approach" way to guess one
	if (empty ( $host )) {
		if (! empty ( $config ['server_name'] )) {
			$host = $config ['server_name'];
		} else if (! empty ( $config ['cookie_domain'] )) {
			$host = (strpos ( $config ['cookie_domain'], '.' ) === 0) ? substr ( $config ['cookie_domain'], 1 ) : $config ['cookie_domain'];
		} else {
			// Set to OS hostname or localhost
			$host = (function_exists ( 'php_uname' )) ? php_uname ( 'n' ) : 'localhost';
		}
	}
		
	// It may be still no valid host, but for sure only a hostname (we may further expand on the cookie domain... if set)
	return $host;
}

3、$_SERVER ['PHP_SELF'] 获得当前脚本文件的路径

4、$_SERVER ['QUERY_STRING'] 查询字符串

5、$_SERVER ['REQUEST_URI'] 获得当前脚本文件的路径及后面的查询参数组成的字符串

6、$_SERVER["HTTP_X_FORWARDED_FOR"] 获得代理服务器的服务器名以及端口,可能有很多,以“,”分割

7、$_SERVER ['REQUEST_METHOD'] 获得访问页面时的请求方法。例如:“GET”、“HEAD”、“POST”、“PUT”


转载请注明:康瑞部落 » php学习笔记
分享好友

分享这个小栈给你的朋友们,一起进步吧。

康瑞部落
创建时间:2020-05-21 17:48:23
本小栈的内容主要包括以下几个方面: 1、有关计算机项目开发的个人心得 2、有关算法与数据结构方面的研究 3、其他计算机相关知识 4、读书笔记与书摘 5、个人兴趣的交流 6、生活琐事的记录 7、转载的美文
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

栈主、嘉宾

查看更多
  • Ruiyuan Li
    栈主

小栈成员

查看更多
  • 栈栈
  • 一号管理员
  • gaokeke123
  • chengxuwei
戳我,来吐槽~