오류가 있습니다. 아래 코드는 페이스 북과 유사한 링크 미리보기 스크립트입니다. 그러나 문제는 내가 입력 한 URL이 https://www.facebook.com
인데 fb 로고가 표시되면 Google 크롬 로고가 표시됩니다.링크 미리보기 스크립트로 오류가 발생했습니다
코드 브라우저
<?php
$url = $_POST['url'];
$url = url_clean($url);
//clean url
function url_clean($ini_url)
{
$uri = trim($ini_url);
if (get_magic_quotes_gpc())
{
$uri = stripslashes($uri);
}
$uri = strtr($uri, array_flip(get_html_translation_table(HTML_ENTITIES)));
$uri = strip_tags($uri);
$uri = htmlspecialchars($uri);
return $uri;
}
//strip the url
function domain_strip($url)
{
if(filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === FALSE)
{
return false;
}
/*** get the url parts ***/
$parts = parse_url($url);
/*** return the host domain ***/
return $parts['host'];
}
//get the information
function get_dat($clean_url)
{
$web_site = fopen($clean_url, "r");
if (!$web_site)
{
exit("Error");
}
$info = '';
while (!feof($web_site))
{
$info .= fgets($web_site, 1024);
}
return $info;
}
$string = get_dat($url);
/// get title
$title_regex = "/<title>(.+)<\/title>/i";
preg_match_all($title_regex, $string, $title, PREG_PATTERN_ORDER);
$url_title = $title[1];
/// get decription
$tags = get_meta_tags($url);
// fetch images
$image_regex = '/<img[^>]*'.'src=[\"|\'](.*)[\"|\']/Ui';
preg_match_all($image_regex, $string, $img, PREG_PATTERN_ORDER);
$images_array = $img[1];
?>
<div class="link_prev_container">
<!----image_cont----->
<?php
if(!$images_array)
{
echo '';
}
else
{
echo '<div class="image_holder">';
$k=1;
for ($i=0;$i<=sizeof($images_array);$i++)
{
if(@$images_array[$i])
{
if(@getimagesize(@$images_array[$i]))
{
list($width, $height, $type, $attr) = getimagesize(@$images_array[$i]);
if($width >= 50 && $height >= 50){
echo "<img src='"[email protected]$images_array[$i]."' width='100' id='".$k."' >";
$k++;
}
}
}
}
echo '</div>';
}
?>
<!----text inf----->
<div class="text_inf_holder">
<div class="title_container"><?php echo substr(@$url_title[0],0,40) ?></div>
<div class="brief_container"><?php echo @$tags['description']; ?></div>
<div class="link_container"><a class="link" href="<?php echo $url; ?>"><?php echo domain_strip($url) ?></a></div>
</div>
</div>
내 질문을 업데이트 : 위의 스크립트가 아님을 검색 페이스 북의 linkpreview 스크립트는 무엇인가?
스크래핑 중에 사용자 에이전트를 지정하지 않았기 때문에 Facebook에서 Google 크롬 웹 사이트로 리디렉션 할 수 있습니까? – Ignas
Facebook이 사용자 에이전트 문자열을보고 "브라우저"가 너무 오래되었음을 확인했습니다 – WizKid
@Ignas im new이에요. –