소켓으로 url 존재 여부 확인 > php

본문 바로가기
사이트 내 전체검색

php

소켓으로 url 존재 여부 확인

페이지 정보

작성자 서방님 댓글 0건 조회 116회 작성일 16-07-26 09:59

본문

http://php.net/manual/en/function.fsockopen.php



 

 

function url_exists($url) {

    $url = str_replace("http://", "", $url);

    if (strstr($url, "/")) {

        $url = explode("/", $url, 2);

        $url[1] = "/".$url[1];

    } else {

        $url = array($url, "/");

    }

 

    $fso = fsockopen($url[0], 80);

    if ($fso) {

        fputs($fso, "GET ".$url[1]." HTTP/1.1\nHost:".$url[0]."\n\n");

        $gets = fgets($fso, 4096);

        fclose($fso);

 

        if (preg_match('/^HTTP\/.* 200 OK/',$gets)){

            return TRUE;

        } else {

            return FALSE;

        }

    } else {

        return FALSE;

    }

}

 

 

 

덤으로.. https 일경우 처리를 위한 조건절이다.

 

switch ($url_info['scheme']) {

case 'https':

$scheme = 'ssl://';

$port = 443;

break;

case 'http':

default:

$scheme = '';

$port = 80;    

}

 

댓글목록

등록된 댓글이 없습니다.

Total 612건 15 페이지
게시물 검색

회원로그인

접속자집계

오늘
163
어제
163
최대
1,347
전체
154,697
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.