t3用友sqlserver口令科迈连接的 请求server/CmxGetLoginType.php失败

在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。
问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
发起http请求后
network会显示各类加载的资源,php有什么办法获取某一type的name
size等信息吗?
HEAD协议可行吗?
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
描述不是很清楚,你是希望:
服务器端主动去发起一个请求去拿信息? =& 可行
还是等客户端网页加载完成之后上报服务器浏览器获取到的信息? =& 不可行
对于1,curl是可以的一个方案,不一定需要使用HEAD方式,GET,POST,DELETE,PUT方式你都可以拿到返回的HTTP头,只要你加上CURLOPT_HEADER参数
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_URL, "http://sf.gg/");
$response = curl_exec($ch);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headerText = substr($response, 0, $headerSize);
$bodyText = substr($response, $headerSize);
echo $headerT //即获取的http头,你会看到还有一次302跳转
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
$info = curl_getinfo($ch);
打印出$info后就有你需要的
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
$SERVER['PHPSELF'] #当前正在执行脚本的文件名,与 document root相关。$_SERVER['argv'] #传递给该脚本的参数。$_SERVER['argc'] #包含传递给程序的命令行参数的个数(如果运行在命令行模式)。$SERVER['GATEWAYINTERFACE'] #服务器使用的 CGI 规范的版本。例如,“CGI/1.1”。$SERVER['SERVERNAME'] #当前运行脚本所在服务器主机的名称。$SERVER['SERVERSOFTWARE'] #服务器标识的字串,在响应请求时的头部中给出。$SERVER['SERVERPROTOCOL'] #请求页面时通信协议的名称和版本。例如,“HTTP/1.0”。$SERVER['REQUESTMETHOD'] #访问页面时的请求方法。例如:“GET”、“HEAD”,“POST”,“PUT”。$SERVER['QUERYSTRING'] #查询(query)的字符串。$SERVER['DOCUMENTROOT'] #当前运行脚本所在的文档根目录。在服务器配置文件中定义。$SERVER['HTTPACCEPT'] #当前请求的 Accept: 头部的内容。$SERVER['HTTPACCEPT_CHARSET'] #当前请求的 Accept-Charset: 头部的内容。例如:“iso-8859-1,*,utf-8”。$SERVER['HTTPACCEPT_ENCODING'] #当前请求的 Accept-Encoding: 头部的内容。例如:“gzip”。$SERVER['HTTPACCEPT_LANGUAGE']#当前请求的 Accept-Language: 头部的内容。例如:“en”。$SERVER['HTTPCONNECTION'] #当前请求的 Connection: 头部的内容。例如:“Keep-Alive”。$SERVER['HTTPHOST'] #当前请求的 Host: 头部的内容。$SERVER['HTTPREFERER'] #链接到当前页面的前一页面的 URL 地址。$SERVER['HTTPUSERAGENT'] #当前请求的 UserAgent: 头部的内容。$_SERVER['HTTPS'] — 如果通过https访问,则被设为一个非空的值(on),否则返回off$SERVER['REMOTEADDR'] #正在浏览当前页面用户的 IP 地址。$SERVER['REMOTEHOST'] #正在浏览当前页面用户的主机名。$SERVER['REMOTEPORT'] #用户连接到服务器时所使用的端口。$SERVER['SCRIPTFILENAME'] #当前执行脚本的绝对路径名。$SERVER['SERVERADMIN'] #管理员信息$SERVER['SERVERPORT'] #服务器所使用的端口$SERVER['SERVERSIGNATURE'] #包含服务器版本和虚拟主机名的字符串。$SERVER['PATHTRANSLATED'] #当前脚本所在文件系统(不是文档根目录)的基本路径。$SERVER['SCRIPTNAME'] #包含当前脚本的路径。这在页面需要指向自己时非常有用。$SERVER['REQUESTURI'] #访问此页面所需的 URI。例如,“/index.html”。$SERVER['PHPAUTH_USER'] #当 PHP 运行在 Apache 模块方式下,并且正在使用 HTTP 认证功能,这个变量便是用户输入的用户名。$SERVER['PHPAUTH_PW'] #当 PHP 运行在 Apache 模块方式下,并且正在使用 HTTP 认证功能,这个变量便是用户输入的密码。$SERVER['AUTHTYPE'] #当 PHP 运行在 Apache 模块方式下,并且正在使用 HTTP 认证功能,这个变量便是认证的类型。
同步到新浪微博
分享到微博?
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。PHP 取得服务器响应一个 HTTP 请求所发送的所有标头
在线手册:&
以上例程的输出类似于:
[0] =& HTTP/1.1 200 OK
[1] =& Date: Sat, 29 May :13 GMT
[2] =& Server: Apache/1.3.27 (Unix)
(Red-Hat/Linux)
[3] =& Last-Modified: Wed, 08 Jan :55 GMT
[4] =& ETag: &3f80f-1b6-3e1cb03b&
[5] =& Accept-Ranges: bytes
[6] =& Content-Length: 438
[7] =& Connection: close
[8] =& Content-Type: text/html
[0] =& HTTP/1.1 200 OK
[Date] =& Sat, 29 May :14 GMT
[Server] =& Apache/1.3.27 (Unix)
(Red-Hat/Linux)
[Last-Modified] =& Wed, 08 Jan :55 GMT
[ETag] =& &3f80f-1b6-3e1cb03b&
[Accept-Ranges] =& bytes
[Content-Length] =& 438
[Connection] =& close
[Content-Type] =& text/html
Example #2
get_headers() using HEAD example
&?php//&By&default&get_headers&uses&a&GET&request&to&fetch&the&headers.&If&you//&want&to&send&a&HEAD&request&instead,&you&can&do&so&using&a&stream&context:stream_context_set_default(&&&&array(&&&&&&&&'http'&=&&array(&&&&&&&&&&&&'method'&=&&'HEAD'&&&&&&&&)&&&&));$headers&=&get_headers('http://example.com');?&
在线手册:&
It should be noted that rather than returning &false& on failure, this function (and others) return a big phat WARNING that will halt your script in its tracks if you do not have error reporting /warning turned off.
Thats just insane!
Any function that does something like fetch a URL should simply return false, without a warning, if the URL fails for whatever reason other than it is badly formatted.
I found that this function is the slowest in obtaining the headers of a page probably because it uses a GET request rather then a HEAD request. Over 10,000,000 trials of obtaining the headers of a page from a server i found the following (results in seconds).
cURL: Mean: 0.. Sigma: 0..
fsocketopen: Mean: 0.. Sigma: 0..
get_headers: Mean: 0.. Sigma: 0..
cURL was the fastest with fsocketopens being the second fastest. I noticed as well that fsocketopen had some outliers where as cURL did not.
Unfortunately&there&is&still&no&useful&output&format&to&handle&redirects.
This&function&will&bring&all&non-broken&headers&into&a&usable&format.&Too&bad&it&has&to&call&the&get_headers()&funtion&2&times,&but&i&dont&see&any&other&possibility&right&now.
&?php
function&page_get_headers($crawl_uri)&{
&&&&//&get&the&array&values&where&to&split&the&second&get&headers&return
&&&&$headers&=&get_headers($crawl_uri,&1);
&&&&if&(empty($headers))&{
&&&&&&&&return&array();
&&&&}
&&&&$splitmarks&=&array();
&&&&foreach&($headers&as&$key=&$h)&{
&&&&&&&&if&(is_numeric($key))&{
&&&&&&&&&&&&array_push($splitmarks,&$h);
&&&&&&&&}
&&&&}
&&&&//&get&the&"real"&headers
&&&&$headers_final&=&array();
&&&&$i&=&0;
&&&&$headers&=&get_headers($crawl_uri);
&&&&foreach&($headers&as&$head)&{
&&&&&&&&//&if&the&value&is&one&of&the&splitmarks,&start&the&next&header
&&&&&&&&if&(array_key_exists($i,&$splitmarks)&&&&$head&===&$splitmarks[$i])&{
&&&&&&&&&&&&$i++;
&&&&&&&&}&&&
&&&&&&&&else&{
&&&&&&&&&&&&//&get&the&headers&name
&&&&&&&&&&&&$tmp&=&explode(":&",&$head,&2);
&&&&&&&&&&&&//&check&if&the&header&is&already&existing,&if&yes,&parse&the&similar&header&to&an&array
&&&&&&&&&&&&if&(!empty($headers_final[$i-1][$tmp[0]]))&{
&&&&&&&&&&&&&&&&if&(is_array($headers_final[$i-1][$tmp[0]]))&{
&&&&&&&&&&&&&&&&&&&&array_push($headers_final[$i-1][$tmp[0]],&$tmp[1]);
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&else&{
&&&&&&&&&&&&&&&&&&&&$headers_final[$i-1][$tmp[0]]&=&array($headers_final[$i-1][$tmp[0]],&$tmp[1]);
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&}
&&&&&&&&&&&&else&{
&&&&&&&&&&&&&&&&$headers_final[$i-1][$tmp[0]]&=&$tmp[1];&&&
&&&&&&&&&&&&}&&&
&&&&&&&&}
&&&&}
&&&&return&$headers_final;
}
?&
Note&that&get_headers&**WILL&follow&redirections**&(HTTP&redirections).&New&headers&will&be&appended&to&the&array&if&$format=0.&If&$format=1&each&redundant&header&will&be&an&array&of&multiple&values,&one&for&each&redirection.
For&example:
&?php
$url&=&'http://google.com';
var_dump(get_headers($url,0));
/*array(18)&{
&&[0]=&&&string(30)&"HTTP/1.0&301&Moved&Permanently"
&&[1]=&&&string(32)&"Location:&http://www.google.com/"
&&[2]=&&&string(38)&"Content-Type:&text/&charset=UTF-8"
&&[3]=&&&string(35)&"Date:&Sun,&26&Sep&:50&GMT"
&&[4]=&&&string(38)&"Expires:&Tue,&26&Oct&:50&GMT"
&&[5]=&&&string(38)&"Cache-Control:&public,&max-age=2592000"
....
&&string(15)&"HTTP/1.0&200&OK"
&&[10]=&&&string(35)&"Date:&Sun,&26&Sep&:51&GMT"
&&[11]=&&&string(11)&"Expires:&-1"
&&[12]=&&&string(33)&"Cache-Control:&private,&max-age=0"
.....
}*/
/*===========================*/
var_dump(get_headers($url,1));
/*array(11)&{
&&[0]=&
&&string(30)&"HTTP/1.0&301&Moved&Permanently"
&&["Location"]=&&&string(22)&"http://www.google.com/"
&&["Content-Type"]=&&&array(2)&{
&&&&[0]=&&&&&string(24)&"text/&charset=UTF-8"
&&&&[1]=&&&&&string(29)&"text/&charset=ISO-8859-1"
&&}
&&["Date"]=&&&array(2)&{
&&&&[0]=&&&&&string(29)&"Sun,&26&Sep&:39&GMT"
&&&&[1]=&&&&&string(29)&"Sun,&26&Sep&:39&GMT"
&&}
&&["Expires"]=&&&array(2)&{
&&&&[0]=&&&&&string(29)&"Tue,&26&Oct&:39&GMT"
&&&&[1]=&&&&&string(2)&"-1"
&&}
&&["Cache-Control"]=&&&array(2)&{
&&&&[0]=&&&&&string(23)&"public,&max-age=2592000"
&&&&[1]=&&&&&string(18)&"private,&max-age=0"
&&}
.....
}*/
?&
Seems&like&there&are&some&people&who&are&looking&for&only&the&3-digit&HTTP&response&code&&-&here&is&a&quick&and&nasty&solution:&?phpfunction&get_http_response_code($theURL)&{&&&&$headers&=&get_headers($theURL);&&&&return&substr($headers[0],&9,&3);}?&How&easy&is&that?&Echo&the&function&containing&the&URL&you&want&to&check&the&response&code&for,&and&voilà.&Custom&redirects,&alternative&for&blocked&is_file()&or&flie_exists()&functions&(like&I&seem&to&have&on&my&servers)&hence&the&cheap&workaround.&But&hey&-&it&works!Pudding
&?php/**&*&Fetches&all&the&real&headers&sent&by&the&server&in&response&to&a&HTTP&request&without&redirects&*&*&@link&&&&&&http://php.net/function.get_headers&*&@link&&&&&&http://bugs.php.net/bug.php?id=50719&&*/function&get_real_headers($url,$format=0,$follow_redirect=0)&{&&if&(!$follow_redirect)&{&&&&//set&new&default&options&&&&$opts&=&array('http'&=&&&&&&&&&array('max_redirects'=&1,'ignore_errors'=&1)&&&&);&&&&stream_context_get_default($opts);&&}&&//get&headers&&&&$headers=get_headers($url,$format);&&&&//restore&default&options&&if&(isset($opts))&{&&&&$opts&=&array('http'&=&&&&&&&&&array('max_redirects'=&20,'ignore_errors'=&0)&&&&);&&&&stream_context_get_default($opts);&&}&&//return&&&&return&$headers;}?&
In&some&cases,&you&don't&want&get_headers&to&follow&redirects.&For&example,&some&of&my&servers&can&access&a&particular&website,&which&sends&a&redirect&header.&The&site&it&is&redirected&to,&however,&has&me&firewalled.&I&need&to&take&the&302&redirected&url,&and&do&something&to&it&to&give&me&a&new&url&that&I&*can*&connect&to.
The&following&will&give&you&output&similar&to&get_headers,&except&it&has&a&timeout,&and&it&doesn't&follow&redirects:
&?php
function&get_headers_curl($url)
{
&&&&$ch&=&curl_init();
&&&&curl_setopt($ch,&CURLOPT_URL,&&&&&&&&&&&&$url);
&&&&curl_setopt($ch,&CURLOPT_HEADER,&&&&&&&&&true);
&&&&curl_setopt($ch,&CURLOPT_NOBODY,&&&&&&&&&true);
&&&&curl_setopt($ch,&CURLOPT_RETURNTRANSFER,&true);
&&&&curl_setopt($ch,&CURLOPT_TIMEOUT,&&&&&&&&15);
&&&&$r&=&curl_exec($ch);
&&&&$r&=&split("\n",&$r);
&&&&return&$r;
}
If&you&do&want&to&follow&redirects,&you&can&do&something&like&this:
$go&=&1;
$i&=&1;
while&($go&&&&$i&&&6)
{
&&&&$headers&=&get_headers_curl($url);
&&&&$go&=&getNextLocation($headers);
&&&&if&($go)
&&&&{
&&&&&&&&$url&=&modifyUrl($go);
&&&&}
&&&&$i++;
}
function&getNextLocation($headers)
{
&&&&$array&=&$headers;
&&&&$count&=&count($array);
&&&&for&($i=0;&$i&&&$count;&$i++)
&&&&{
&&&&&&&&if&(strpos($array[$i],&"ocation:"))
&&&&&&&&{
&&&&&&&&&&&&&&&&$url&=&substr($array[$i],&10);
&&&&&&&&}
&&&&}
&&&&if&($url)
&&&&{
&&&&&&&&return&$url;
&&&&}
&&&&else
&&&&{
&&&&&&&&return&0;
&&&&}
}
?&
Should&be&the&same&than&the&original&get_headers():
&?php
if&(!function_exists('get_headers'))&{
function&get_headers($url,&$format=0)&{
&&&&$headers&=&array();
&&&&$url&=&parse_url($url);
&&&&$host&=&isset($url['host'])&?&$url['host']&:&'';
&&&&$port&=&isset($url['port'])&?&$url['port']&:&80;
&&&&$path&=&(isset($url['path'])&?&$url['path']&:&'/')&.&(isset($url['query'])&?&'?'&.&$url['query']&:&'');
&&&&$fp&=&fsockopen($host,&$port,&$errno,&$errstr,&3);
&&&&if&($fp)
&&&&{
&&&&&&&&$hdr&=&"GET&$path&HTTP/1.1\r\n";
&&&&&&&&$hdr&.=&"Host:&$host&\r\n";
&&&&&&&&$hdr&.=&"Connection:&Close\r\n\r\n";
&&&&&&&&fwrite($fp,&$hdr);
&&&&&&&&while&(!feof($fp)&&&&$line&=&trim(fgets($fp,&1024)))
&&&&&&&&{
&&&&&&&&&&&&if&($line&==&"\r\n")&
&&&&&&&&&&&&list($key,&$val)&=&explode(':&',&$line,&2);
&&&&&&&&&&&&if&($format)
&&&&&&&&&&&&&&&&if&($val)&$headers[$key]&=&$val;
&&&&&&&&&&&&&&&&else&$headers[]&=&$key;
&&&&&&&&&&&&else&$headers[]&=&$line;
&&&&&&&&}
&&&&&&&&fclose($fp);
&&&&&&&&return&$headers;
&&&&}
&&&&return&false;
}
}
?&
I&tried&to&replicate&the&native&behavior&as&much&as&possible&for&systems&that&don't&have&the&get_headers()&function.&Here&it&is:&?phpif&(!function_exists('get_headers'))&{function&get_headers($Url,&$Format=&0,&$Depth=&0)&{&&&&if&($Depth&&&5)&&&&&$Parts&=&parse_url($Url);&&&&if&(!array_key_exists('path',&$Parts))&&&$Parts['path']&=&'/';&&&&if&(!array_key_exists('port',&$Parts))&&&$Parts['port']&=&80;&&&&if&(!array_key_exists('scheme',&$Parts))&$Parts['scheme']&=&'http';&&&&$Return&=&array();&&&&$fp&=&fsockopen($Parts['host'],&$Parts['port'],&$errno,&$errstr,&30);&&&&if&($fp)&{&&&&&&&&$Out&=&'GET&'.$Parts['path'].(isset($Parts['query'])&?&'?'.@$Parts['query']&:&'')."&HTTP/1.1\r\n".&&&&&&&&&&&&&&&'Host:&'.$Parts['host'].($Parts['port']&!=&80&?&':'.$Parts['port']&:&'')."\r\n".&&&&&&&&&&&&&&&'Connection:&Close'."\r\n";&&&&&&&&fwrite($fp,&$Out."\r\n");&&&&&&&&$Redirect&=&false;&$RedirectUrl&=&'';&&&&&&&&while&(!feof($fp)&&&&$InLine&=&fgets($fp,&1280))&{&&&&&&&&&&&&if&($InLine&==&"\r\n")&&&&&&&&&&&&&$InLine&=&rtrim($InLine);&&&&&&&&&&&&list($Key,&$Value)&=&explode(':&',&$InLine,&2);&&&&&&&&&&&&if&($Key&==&$InLine)&{&&&&&&&&&&&&&&&&if&($Format&==&1)&&&&&&&&&&&&&&&&&&&&&&&&$Return[$Depth]&=&$InLine;&&&&&&&&&&&&&&&&else&&&&$Return[]&=&$InLine;&&&&&&&&&&&&&&&&if&(strpos($InLine,&'Moved')&&&0)&$Redirect&=&true;&&&&&&&&&&&&}&else&{&&&&&&&&&&&&&&&&if&($Key&==&'Location')&$RedirectUrl&=&$Value;&&&&&&&&&&&&&&&&if&($Format&==&1)&&&&&&&&&&&&&&&&&&&&&&&&$Return[$Key]&=&$Value;&&&&&&&&&&&&&&&&else&&&&$Return[]&=&$Key.':&'.$Value;&&&&&&&&&&&&}&&&&&&&&}&&&&&&&&fclose($fp);&&&&&&&&if&($Redirect&&&&!empty($RedirectUrl))&{&&&&&&&&&&&&$NewParts&=&parse_url($RedirectUrl);&&&&&&&&&&&&if&(!array_key_exists('host',&$NewParts))&&&$RedirectUrl&=&$Parts['host'].$RedirectUrl;&&&&&&&&&&&&if&(!array_key_exists('scheme',&$NewParts))&$RedirectUrl&=&$Parts['scheme'].'://'.$RedirectUrl;&&&&&&&&&&&&$RedirectHeaders&=&get_headers($RedirectUrl,&$Format,&$Depth+1);&&&&&&&&&&&&if&($RedirectHeaders)&$Return&=&array_merge_recursive($Return,&$RedirectHeaders);&&&&&&&&}&&&&&&&&return&$Return;&&&&}&&&&return&false;}}?&The&function&will&handle&up&to&five&redirects.Enjoy!
Content-Type returns a value depending only on the extension and not the real MIME TYPE.
So, bad_file.exe renamed to good_file.doc will return application/msword
A file without extension returns a 404.
I've&noticed&it.Some&Server&will&simply&return&the&false&reply&header&if&you&sent&'HEAD'&request&instead&of&'GET'.&The&'GET'&request&header&always&receiving&the&most&actual&HTTP&header&instead&of&'HEAD'&request&header.&But&If&you&don't&mind&for&a&fast&but&risky&method&then&'HEAD'&request&is&better&for&you.btw&...&this&is&get&header&with&additional&information&such&as&User,&Pass&&&Refferer.&...&&?php&&&&function&get_headers_x($url,$format=0,&$user='',&$pass='',&$referer='')&{&&&&&&&&if&(!empty($user))&{&&&&&&&&&&&&$authentification&=&base64_encode($user.':'.$pass);&&&&&&&&&&&&$authline&=&"Authorization:&Basic&$authentification\r\n";&&&&&&&&}&&&&&&&&if&(!empty($referer))&{&&&&&&&&&&&&$refererline&=&"Referer:&$referer\r\n";&&&&&&&&}&&&&&&&&$url_info=parse_url($url);&&&&&&&&$port&=&isset($url_info['port'])&?&$url_info['port']&:&80;&&&&&&&&$fp=fsockopen($url_info['host'],&$port,&$errno,&$errstr,&30);&&&&&&&&if($fp)&{&&&&&&&&&&&&$head&=&"GET&".@$url_info['path']."?".@$url_info['query']."&HTTP/1.0\r\n";&&&&&&&&&&&&if&(!empty($url_info['port']))&{&&&&&&&&&&&&&&&&$head&.=&"Host:&".@$url_info['host'].":".$url_info['port']."\r\n";&&&&&&&&&&&&}&else&{&&&&&&&&&&&&&&&&$head&.=&"Host:&".@$url_info['host']."\r\n";&&&&&&&&&&&&}&&&&&&&&&&&&$head&.=&"Connection:&Close\r\n";&&&&&&&&&&&&$head&.=&"Accept:&*/*\r\n";&&&&&&&&&&&&$head&.=&$refererline;&&&&&&&&&&&&$head&.=&$authline;&&&&&&&&&&&&$head&.=&"\r\n";&&&&&&&&&&&&fputs($fp,&$head);&&&&&&&&&&&&&&&&&&&while(!feof($fp)&or&($eoheader==true))&{&&&&&&&&&&&&&&&&if($header=fgets($fp,&1024))&{&&&&&&&&&&&&&&&&&&&&if&($header&==&"\r\n")&{&&&&&&&&&&&&&&&&&&&&&&&&$eoheader&=&true;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&else&{&&&&&&&&&&&&&&&&&&&&&&&&$header&=&trim($header);&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&if($format&==&1)&{&&&&&&&&&&&&&&&&&&&&$key&=&array_shift(explode(':',$header));&&&&&&&&&&&&&&&&&&&&&&&&if($key&==&$header)&{&&&&&&&&&&&&&&&&&&&&&&&&&&&&$headers[]&=&$header;&&&&&&&&&&&&&&&&&&&&&&&&}&else&{&&&&&&&&&&&&&&&&&&&&&&&&&&&&$headers[$key]=substr($header,strlen($key)+2);&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&unset($key);&&&&&&&&&&&&&&&&&&&&}&else&{&&&&&&&&&&&&&&&&&&&&&&&&$headers[]&=&$header;&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&}&&&&&&&&&&&&return&$headers;&&&&&&&&}&else&{&&&&&&&&&&&&return&false;&&&&&&&&}&&&&}?&Regards.Donovan
If you want to get headers that current PHP process is going to send back to browser, see headers_list()
hey,&i&came&across&this&afew&weeks&ago&and&used&the&function&in&an&app&for&recording&info&about&domains&that&my&company&owns,&and&found&that&the&status&this&returns&was&wrong&most&of&the&time&(400&bad&request&or&void&for&sites&that&were&clearly&online).&then&looking&into&it&i&noticed&the&problem&was&that&it&wasn't&able&to&get&the&correct&info&about&sites&with&redirections.&but&thats&not&the&full&problem&because&everything&on&my&server&was&returning&the&wrong&status&too.&i&searched&around&on&php.net&for&other&info&and&found&that&fsockopen's&example&worked&better&and&only&needed&some&tweeking.
heres&the&function&i&put&together&from&it&and&a&small&change.
&?php
if(!function_exists('get_headers'))&{
&&&function&get_headers($url,$format=0,$httpn=0){
&&&&$fp&=&fsockopen($url,&80,&$errno,&$errstr,&30);
&&&&if&($fp)&{
&&&&&&&$out&=&"GET&/&HTTP/1.1\r\n";
&&&&&&&$out&.=&"Host:&$url\r\n";
&&&&&&&$out&.=&"Connection:&Close\r\n\r\n";
&&&&&&&fwrite($fp,&$out);
&&&&&&&while&(!feof($fp))&{
&&&&&&&&&&&$var.=fgets($fp,&1280);
&&&&&&&}
&&&&$var=explode("&",$var);
&&&&$var=$var[0];
&&&&$var=explode("\n",$var);
&&&&fclose($fp);
&&&&return&$var;
&&&&}
&&&&}
}
?&
this&returns&an&array&of&the&header&(only&problem&being&that&if&the&site&doesn't&have&correct&html&it'll&pull&in&some&content&too).
hope&this'll&help&someone&else.
The&replacement&updated&get_headers&function&by&aeontech&at&gmail&dot&com&improperly&formats&dates&when&$format&=&1.Replace:&?else&{$headers[strtolower($h2[0])]&=&trim($h2[1]);}?&With:&?else&{&&&&$foo&=&implode(&':',&$h2&);$foo&=&preg_replace(&'/[a-zA-Z-&]*:&/',&'',&$foo&);$headers[strtolower($h2[0])]&=&trim(&$foo&);}
aeontech, this the below change adds support for SSL connections. Thanks for the code!
if (isset($url_info['scheme']) && $url_info['scheme'] == 'https') {
$port = 443;
$fp=fsockopen('ssl://'.$url_info['host'], $port, $errno, $errstr, 30);
$port = isset($url_info['port']) ? $url_info['port'] : 80;
$fp=fsockopen($url_info['host'], $port, $errno, $errstr, 30);
For&anyone&reading&the&previous&comments,&here&is&code&that&takes&into&account&all&the&previous&suggestions&and&includes&a&bugfix,&too.This&code&basically&provides&the&"get_headers"&function&even&on&systems&that&are&not&running&PHP&5.0.&&It&uses&strtolower()&on&the&keys,&as&suggested.&&It&uses&the&$h2&array&instead&of&the&$key,&as&suggested.&&It&removes&a&line&about&unsetting&the&$key&--&no&reason&to&unset&something&which&is&no&longer&used.&&And&I've&changed&the&status&header&to&be&named&"status"&(instead&of&"0")&in&the&array.&&Note&that&if&more&than&one&header&is&returned&without&a&label,&they'll&be&stuck&in&"status"&--&but&I&think&status&is&the&only&header&that&comes&back&without&a&label,&so&it&works&for&me.&&So,&first&the&code,&then&a&sample&of&the&usage:&?phpif(!function_exists('get_headers'))&{&&&/**&&&*&@return&array&&&&*&@param&string&$url&&&&*&@param&int&$format&&&&*&@desc&Fetches&all&the&headers&&&&*&@author&cpurruc&fh-landshut&de&&&&*&@modified&by&dotpointer&&&&*&@modified&by&aeontech&&&&*/&&&&function&get_headers($url,$format=0)&{&&&&&&&&$url_info=parse_url($url);&&&&&&&&$port&=&isset($url_info['port'])&?&$url_info['port']&:&80;&&&&&&&&$fp=fsockopen($url_info['host'],&$port,&$errno,&$errstr,&30);&&&&&&&&if($fp)&{&&&&&&&&&&&&$head&=&"HEAD&".@$url_info['path']."?".@$url_info['query'];&&&&&&&&&&&&$head&.=&"&HTTP/1.0\r\nHost:&".@$url_info['host']."\r\n\r\n";&&&&&&&&&&&&fputs($fp,&$head);&&&&&&&&&&&&while(!feof($fp))&{&&&&&&&&&&&&&&&&if($header=trim(fgets($fp,&1024)))&{&&&&&&&&&&&&&&&&&&&&if($format&==&1)&{&&&&&&&&&&&&&&&&&&&&&&&&$h2&=&explode(':',$header);&&&&&&&&&&&&&&&&&&&&&&&&//&the&first&element&is&the&http&header&type,&such&as&HTTP/1.1&200&OK,&&&&&&&&&&&&&&&&&&&&&&&&//&it&doesn't&have&a&separate&name,&so&we&have&to&check&for&it.&&&&&&&&&&&&&&&&&&&&&&&&if($h2[0]&==&$header)&{&&&&&&&&&&&&&&&&&&&&&&&&&&&&$headers['status']&=&$header;&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&&&&&else&{&&&&&&&&&&&&&&&&&&&&&&&&&&&&$headers[strtolower($h2[0])]&=&trim($h2[1]);&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&else&{&&&&&&&&&&&&&&&&&&&&&&&&$headers[]&=&$header;&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&}&&&&&&&&&&&&}&&&&&&&&&&&&return&$headers;&&&&&&&&}&&&&&&&&else&{&&&&&&&&&&&&return&false;&&&&&&&&}&&&&}}?&OK?&&Here's&the&usage:&?php$response&=&get_headers('http://www.example.com/',&1);if&(!$response)&{&&&&echo&'Unable&to&initiate&connection.';}else&{&&&&print_r($response);}?&
aeontech,&I'd&edit&your&function&a&little...&How&about&replacing&this:&?&&&&&&&&&&&&&&&&&&&&&&&$key&=&array_shift(explode(':',$header));&&&&&&&&&&&&&&&&&&&&&&&//&the&first&element&is&the&http&header&type,&such&as&HTTP&200&OK,&&&&&&&&&&&&&&&&&&&&&&&//&it&doesn't&have&a&separate&name,&so&we&have&to&check&for&it.&&&&&&&&&&&&&&&&&&&&&&&if($key&==&$header)&&&&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&&&&$headers[]&=&$&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&&&&$headers[$key]=substr($header,strlen($key)+2);&&&&&&&&&&&&&&&&&&&&&&&}?&with&this:&?&&&&&&&&&&&&&&&&&&&&&&&$h2&=&explode(':',$header);&&&&&&&&&&&&&&&&&&&&&&&//&the&first&element&is&the&http&header&type,&such&as&HTTP/1.1&200&OK,&&&&&&&&&&&&&&&&&&&&&&&//&it&doesn't&have&a&separate&name,&so&we&have&to&check&for&it.&&&&&&&&&&&&&&&&&&&&&&&if($h2[0]&==&$header)&&&&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&&&&$headers[]&=&$&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&&&&$headers[&$h2[0]&]&=&trim($h2[1]);&&&&&&&&&&&&&&&&&&&&&&&}?&I&think&it&looks&a&bit&nicer&:)
After discovering that some webservers reply with &Content-Type& and others with &Content-type& I modified the function below to use strtolower($key) to make for easy checking against these case differences.
In&response&to&dotpointer's&modification&of&Jamaz'&solution...Here&is&a&small&modification&of&your&function,&this&adds&the&emulation&of&the&optional&$format&parameter.&?phpif(!function_exists('get_headers'))&{&&&&&&&&/**&&&&*&@return&array&&&&*&@param&string&$url&&&&*&@param&int&$format&&&&*&@desc&Fetches&all&the&headers&&&&*&@author&cpurruc&fh-landshut&de&&&&*&@modified&by&dotpointer&&&&*&@modified&by&aeontech&&&&*/&&&&function&get_headers($url,$format=0)&&&&{&&&&&&&&$url_info=parse_url($url);&&&&&&&&$port&=&isset($url_info['port'])&?&$url_info['port']&:&80;&&&&&&&&$fp=fsockopen($url_info['host'],&$port,&$errno,&$errstr,&30);&&&&&&&&&&&&&&&&if($fp)&&&&&&&&{&&&&&&&&&&&&$head&=&"HEAD&".@$url_info['path']."?".@$url_info['query']."&HTTP/1.0\r\nHost:&".@$url_info['host']."\r\n\r\n";&&&&&&&&&&&&&&&&&&&fputs($fp,&$head);&&&&&&&&&&&&&&&&&&&while(!feof($fp))&&&&&&&&&&&&{&&&&&&&&&&&&&&&&if($header=trim(fgets($fp,&1024)))&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&if($format&==&1)&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&$key&=&array_shift(explode(':',$header));&&&&&&&&&&&&&&&&&&&&&&&&//&the&first&element&is&the&http&header&type,&such&as&HTTP&200&OK,&&&&&&&&&&&&&&&&&&&&&&&&//&it&doesn't&have&a&separate&name,&so&we&have&to&check&for&it.&&&&&&&&&&&&&&&&&&&&&&&&if($key&==&$header)&&&&&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&&&&&$headers[]&=&$header;&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&&&&&$headers[$key]=substr($header,strlen($key)+2);&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&&&&&unset($key);&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&$headers[]&=&$header;&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&}&&&&&&&&&&&&}&&&&&&&&&&&&return&$headers;&&&&&&&&}&&&&&&&&else&&&&&&&&{&&&&&&&&&&&&return&false;&&&&&&&&}&&&&}}?&

我要回帖

更多关于 用友 请求的名称有效 的文章

 

随机推荐