"함수 is bot()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 하나는 보이지 않습니다)
6번째 줄: 6번째 줄:
[[분류: PHP]]
[[분류: PHP]]
{{참고|PHP is_bot()}}
{{참고|PHP is_bot()}}
<source lang='php'>
<syntaxhighlight lang='php'>
function is_bot() {
function is_bot() {
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
$agent = $_SERVER['HTTP_USER_AGENT'];
if( strpos('googlebot',$agent) !== false ) return true; // 구글
if( strpos($agent,'Googlebot') !== false ) return true; // 구글
if( strpos('bingbot',$agent) !== false ) return true; // 빙
if( strpos($agent,'bingbot') !== false ) return true; // 빙
if( strpos('daum',$agent) !== false ) return true; // 다음
if( strpos($agent,'Daum') !== false ) return true; // 다음
if( strpos('yeti',$agent) !== false ) return true; // 네이버
if( strpos($agent,'Yeti') !== false ) return true; // 네이버
return false;
return false;
}
}
</source>
</syntaxhighlight>

2020년 11월 2일 (월) 02:36 기준 최신판

1 개요[ | ]

함수 is_bot()

2 PHP[ | ]

function is_bot() {
	$agent = $_SERVER['HTTP_USER_AGENT'];
	if( strpos($agent,'Googlebot') !== false ) return true; // 구글
	if( strpos($agent,'bingbot') !== false ) return true; // 빙
	if( strpos($agent,'Daum') !== false ) return true; // 다음
	if( strpos($agent,'Yeti') !== false ) return true; // 네이버
	return false;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}