0

Hey I've a problem with my code. It works fine for the first 10 name, but then "file_get_contents" return just empty strings

Is this a timeout problem? or has it a other reason?

And how can i fix this?

my Code:

<?php
$member;

mysql_connect("localhost","**********","********");
mysql_select_db('bf3_ezstats');
$sql = mysql_query('SELECT id, name FROM ez2bf3_player ORDER BY id ASC');

while($row = mysql_fetch_assoc($sql)){
$member[$row['id']] = $row['name'];
}
mysql_close();
print_r($member);

foreach ($member as $ip => $player){
ini_set('default_socket_timeout', 120);
$SC = file_get_contents('http://battlelog.battlefield.com/bf3/user/'.$player);

$SC = split('<surf:container id="profile-gamereport-previews">',$SC);
$SC = split('</surf:container>',$SC[1])[0];

$IPs = array(0=>$player);
while(strpos($SC,'href') !== false){
    $start = strpos($SC,"href");
    $end = strpos($SC,'"',$start+6);
    $IP= substr($SC,$start,$end-$start);
    $IPs[] = "http://battlelog.battlefield.com".str_replace('href="',"",$IP);
    $SC = substr($SC,$end,strlen($SC)-1);
}
print_r($IPs);

}

?>

M4tho
  • 116
  • 2
  • 13
  • remote firewall might be blocking you. introduce a random `sleep()` delay – DevZer0 Jul 14 '13 at 12:23
  • [dont use mysql_* api its deprecated so either use PDO or mysqli see this](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/14110189#14110189) – NullPoiиteя Jul 14 '13 at 12:31

1 Answers1

-1

file_get_contents() on external URIs is just a huge security issue. This method could lead to many errors, probably including yours.

If you need to work on external servers, through HTTP, I strongly recommand the use of cURL (http://php.net/manual/fr/book.curl.php). You'll find it more handy, I think, and you may save yourself a lot of trouble.

John WH Smith
  • 2,743
  • 1
  • 21
  • 31
  • Actually, there a reason why `allow_url_fopen` is disabled in default configurations. Of course, if you're considering giving a more constructive and elaborate comment, please feel free to do so. – John WH Smith Apr 25 '14 at 16:25