Prerequisites
Determine whether the remote URL is valid. The remote URL includes remote images, webpages, videos, and other elements.
Solution: Use PHP
- Use the file_get_contents function. However, if the URL cannot be accessed, the program will be terminated.
- Use curl to return the result and determine whether the execution is correct.
- Use the get_headers function to check whether 200 exists based on the HTTP return value.
Solve with JS:
- The native JS function activexobject is used and only supports ie kernel browsers.
- Use JQ Extension
This article mainly introduces the third method of PHP solution. This method is rarely used, but it feels good again,
Get_headers must be supported
- Php_openssl supports viewing phpinfo to see if it is enabled
- Allow_url_fopen = on modify PHP. ini and run it remotely.
Function introduction:
ArrayGet_headers(String$ URL[, Int$ Format])
Get_headers ()Returns an array containing the header sent by the server to respond to an HTTP request. If it fails, returnFalseAnd issueE_warningLevel error message.
If the optionalFormatIf the parameter is set to 1Get_headers ()The corresponding information is parsed and the key name of the array is set. For example:
Simple Example:
<? PHP
$ Url = "http://cn.php.net/images/php.gif ";
$ Array = get_headers ($ URL, 1 );
If (preg_match ('/ 200/', $ array [0]) {
Echo "<PRE/> ";
Print_r ($ array );
} Else {
Echo "invalid URL resource! ";
}
Explanation: Determine whether the remote image ur is valid. Determine whether the URL resource is valid based on whether 200 information exists in the returned value HTTP.
Test results:
The returned result is --------------------- test OK.
Advantages and disadvantages:
Enable allow_url_fopen = on. It is a bit similar to the conditions used by the file_get_contents function, but the return value is relatively small. You can use
Function_exists determines whether this method can be used
Other methods to remotely determine whether a URL is valid:
Use the curl method: http://www.windsfly.cn/blog/article.asp? Id = 1647 http://blog.pcsql.com/archives/87.html
Using JS implementation: http://www.cnblogs.com/GuominQiu/archive/2011/04/07/2007600.html
This article is based on the signature-non-commercial use
3.0 release of the license agreement. You are welcome to repost and interpret it. However, the signature of this article, PHP Huaibei (including links), must be retained and cannot be used for commercial purposes. If you have any questions or negotiation with the Authority, please contact me.
Prerequisites
Determine whether the remote URL is valid. The remote URL includes remote images, webpages, videos, and other elements.
Solution: Use PHP
- Use the file_get_contents function. However, if the URL cannot be accessed, the program will be terminated.
- Use curl to return the result and determine whether the execution is correct.
- Use the get_headers function to check whether 200 exists based on the HTTP return value.
Solve with JS:
- The native JS function activexobject is used and only supports ie kernel browsers.
- Use JQ Extension
This article mainly introduces the third method of PHP solution. This method is rarely used, but it feels good again,
Get_headers must be supported
- Php_openssl supports viewing phpinfo to see if it is enabled
- Allow_url_fopen = on modify PHP. ini and run it remotely.
Function introduction:
ArrayGet_headers(String$ URL[, Int$ Format])
Get_headers ()Returns an array containing the header sent by the server to respond to an HTTP request. If it fails, returnFalseAnd issueE_warningLevel error message.
If the optionalFormatIf the parameter is set to 1Get_headers ()The corresponding information is parsed and the key name of the array is set. For example:
Simple Example:
<? PHP
$ Url = "http://cn.php.net/images/php.gif ";
$ Array = get_headers ($ URL, 1 );
If (preg_match ('/ 200/', $ array [0]) {
Echo "<PRE/> ";
Print_r ($ array );
} Else {
Echo "invalid URL resource! ";
}
Explanation: Determine whether the remote image ur is valid. Determine whether the URL resource is valid based on whether 200 information exists in the returned value HTTP.
Test results:
The returned result is --------------------- test OK.
Advantages and disadvantages:
Enable allow_url_fopen = on. It is a bit similar to the conditions used by the file_get_contents function, but the return value is relatively small. You can use
Function_exists determines whether this method can be used
Other methods to remotely determine whether a URL is valid:
Use the curl method: http://www.windsfly.cn/blog/article.asp? Id = 1647 http://blog.pcsql.com/archives/87.html
Using JS implementation: http://www.cnblogs.com/GuominQiu/archive/2011/04/07/2007600.html