Home  >  Article  >  Backend Development  >  链接中@之前的内容是做什么用的?

链接中@之前的内容是做什么用的?

WBOY
WBOYOriginal
2016-06-06 20:50:191112browse

http://username:password@www.sample.com/ 比如这种链接,前面的username:password一般在什么情况下会用到? 在PHP,对于这么一条请求,如何才能获取username:password部分的内容。

回复内容:

http://username:password@www.sample.com/ 比如这种链接,前面的username:password一般在什么情况下会用到? 在PHP,对于这么一条请求,如何才能获取username:password部分的内容。

参见Wiki的HTTP Basic Access Authentication

parse_url

<code><?php $url = 'http://username:password@hostname/path?arg=value#anchor';

print_r(parse_url($url));
?> 
</code>

以上例程会输出:Array ( [scheme] => http [host] => hostname [user] => username [pass] => password [path] => /path [query] => arg=value [fragment] => anchor )

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn