1

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.".

  • When your php is executted, what is the value of: `$text`.... Echo it as well, and check yourself what is that you are receiving. It can be that your string is encoded as something else than the page, and the needle is never found. – Bonatti May 31 '16 at 14:02
  • If I do $print_r($text) and set URL to google.com then google.com shows up in the browser. But when I enter instagram.com it doesn't work. I have tried with and without www, http, https... – Water LOOOOO May 31 '16 at 14:16
  • That is not what is relevant here. The point is, a cURL request is different from a Browser request. It is possible that the Server is replying with something other than `HTTP OK (200)`, it is possible that is replying with other content, it is possible that the Server expects user agents, etc... Too many possibilities. I myself preffer [file_get_contents](http://php.net/manual/en/function.file-get-contents.php) to query other sites. Check documentation on building the Header for your query. – Bonatti May 31 '16 at 14:21
  • I did follow this exact "guide" http://stackoverflow.com/questions/2440729/php-curl-how-can-i-emulate-a-get-request-exactly-like-a-web-browser to mimic a browser. Still does not work nor display the website when I echo it! – Water LOOOOO May 31 '16 at 15:20

1 Answers1

1

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);
iainn
  • 16,826
  • 9
  • 33
  • 40
  • I can't edit my post... But I added that line and it still always return "Username exists.". – Water LOOOOO May 31 '16 at 13:49
  • Not sure what else to suggest, it works fine here with that line added. – iainn May 31 '16 at 13:55
  • Its something with instagram.com. If I do $print_($text) and set URL to google.com then google.com shows up in the browser. But when I enter instagram.com it doesn't work. I have tried with and without www, http, https... – Water LOOOOO May 31 '16 at 14:05