简体   繁体   中英

cURL check if text exists on website

Trying to see if an IG acc is used or free but it always return false even if the account exists...

<?php
$ch = curl_init("http://www.instagram.com/asd9usa0d0sad90sa90a09d");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$text = curl_exec($ch);
$test = strpos($text, "Sorry, this page");

print_r($text);

if ($test==false)
{
    echo "Username exists";
}
else
{
    echo "Username does not exist";
}

?>

If an IG acc doesn't exist, example instagram.com/basdlkasld4 then it will disaplay "Sorry, this page isn't available.".

That URL redirects a couple of times before reaching the Sorry, this page... result. If you add the following line, Curl will follow the redirects correctly.

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM