-3
$instagram = "ugur2d";
$kaynak = file_get_contents("https://www.instagram.com/$instagram/"); 
preg_match('@<title>(.*?)</title>@si', $kaynak, $iglink);
echo $iglink[1];

Screen is empty. How can i run it?

iainn
  • 16,826
  • 9
  • 33
  • 40
Uğur KILCI
  • 55
  • 1
  • 8
  • 1
    Other than the fact [that Instagram account doesn't exist](https://www.instagram.com/ugur2d/), this code works fine for me. Trying a different account displays the title. – iainn Jul 06 '18 at 09:15
  • i guess file_get_contents isnt allowed to use urls on his server... should use curl – Kapsonfire Jul 06 '18 at 09:20

2 Answers2

0

After some checkings... your url returns error 404 - file_get_contents will return false if 404 is returned by the server (instagram returns a 404 error page if profile does not exist)

thats why you dont get any result!

anyway you should use curl instead!

Kapsonfire
  • 1,013
  • 5
  • 17
0

Okey okey okey. Im fixed problem. Answer -> CURL :D

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://toosba.com/',
    CURLOPT_USERAGENT => "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => FALSE
]);

$source = curl_exec($ch);

curl_close($ch);

preg_match('/<title>(.*?)<\/title>/', $source, $title);

print_r($title);
echo "<hr>".$title[1];

Thank you :)

Uğur KILCI
  • 55
  • 1
  • 8