检查URL地址
2016-01-06 10:26
381 查看
set_time_limit(0); function check_url($url) { // Break the URL down into its parts: $url_pieces = parse_url($url); // Set the $path and $port: $path = (isset($url_pieces['path'])) ? $url_pieces['path'] : '/'; $port = (isset($url_pieces['port'])) ? $url_pieces['port'] : 80; // Connect using fsockopen(): if ($fp = fsockopen($url_pieces['host'], $port, $errno, $errstr, 30)) { // Send some data: $send = "HEAD $path HTTP/1.1\r\n"; $send .= "HOST: {$url_pieces['host']}\r\n"; $send .= "CONNECTION: Close\r\n\r\n"; fwrite($fp, $send); // Read the response: $data = fgets($fp, 128); // Close the connection: fclose($fp); // Return the response code: list($response, $code) = explode(' ', $data); if ($code == 200) { return array($code, 'good'); } else { return array($code, 'bad'); } } else { // No connection, return the error message: return array($errstr, 'bad'); } }
相关文章推荐
- QT_thread
- netbeans常用快捷键
- PathVariable有句号或小数点时,取值不全
- 只提供常量阶接口的双链表类模板
- 彻底理解指针
- 跟着和尚一步一步搭建springmvc+springdata-jpa+mybatis+shiro+bootstrap项目(二)
- 112. Path Sum
- netbeans常用快捷键
- IDEA快捷键
- CPPUTest 单元测试框架(针对 C 单元测试的使用说明)
- 《乔布斯的魔力演讲》读书笔记
- ideaic快捷键
- RxJava操作符详述转载
- C#使用checked关键字处理"溢出"错误
- 快的打车架构实践
- ideaic快捷键
- Linux学习之开机启动
- eclipse起不来,也不报错,闪一下就退了,不读条
- 【Python备忘】python判断文件和文件夹是否存在
- kindeditor的简单尝试 maven项目