Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Navigation
Latest Addons
Xbox Leaderboards 9
Cookiebar Panel 73
AD Gallery 153
SyntaxHighlighte... 63
Newsletters v4.03 169
Facebook Like Box 207
Newsletters v4.02 79
Metro 236
Facebook Connect 216
Shoutbox Panel 185
Redactor for PHP... 128
MI Floating Side... 133
Facebook Login/R... 182
Avatar Studio v2.03 215
Relationship Sta... 123
Popular Addons
iTheme2 5911
Arise 5871
User Control v1.23 4684
Event Calendar 4138
Photowidget panel 3923
Radio-Theme red2... 3396
Highslide Gallery 3361
CSS/JavaScript D... 3277
Facebook Connect... 3057
Dynamic Menu 2948
Slideshow Lightb... 2770
L-AMANT 2689
Enigma 2671
2Dark 2625
Black 2621
View Thread
Who is here? 1 guest(s)
 Print Thread
Anyone know how to fix file_get_contents Error?
Craig
Hi,

If using file_get_contents to get the status of a site or whatever and if you have entered a url that does not exist or down it will fail and produce the error...

file_get_contents() [<a href='function.file-get-contents'>function.file-get-contents</a>]: php_network_getaddresses: getaddrinfo failed: Name or service not known


So example,
I have entered a url that does not exist like....

Download source  Code
http://www.php-fangree.co.uk




So this....

Download source  Code
<?php
   
$url = "http://www.php-fangree.co.uk";


$contents = @file_get_contents($url);


if ($contents){
echo "<span style='color: green;'> OK</span> ";
} else {
echo "<span style='color: red;'> NOT OK</span> ";
}
       

?>




Produces the error but the point is to see if the site is on-line or not so if the site is going to be off-line or does not exist then what's the point if it is going to throw this error every time the wrong URL is entered or every time a site is down.

Now as you see in the code I have added @ before file_get_contents to suppress the error, however this will still produce the error in the PHP-Fusion log.

Does anyone know what I can do so it will NOT produce the error if a site is not on-line or wrong URL or can anyone show me a better way or different function to do it that will not produce errors if things are down?

Thanks
 
http://www.fusiontube.co.uk/
Richard Ainz
There is some kind of script checking sites on the page with the NSS list on this site. Could it be related?
Community Moderation Management & Support Team Leader
Owner of: www.php-fusion.se | www.php-fusion.net | www.php-fusion.us | www.php-fusion.mobi
Who the hell thought "erectus" was a good species name for our ancestors?
 
www.php-fusion.se
Craig
The License Violations DB on next does it but I am not sure how that handles errors if the site is down or does not exist.
 
http://www.fusiontube.co.uk/
DrunkeN
If you want check if site is available then you can use this function
Download source  Code
   function check_url($url) {
           if(!filter_var($url, FILTER_VALIDATE_URL)) {
              return "<span style='color: orange; font-size: 14px; font-weight: bold;'>URL provided wasn't valid</span>";
           }
           $ul = curl_init($url);
           curl_setopt($ul, CURLOPT_CONNECTTIMEOUT, 10);
           curl_setopt($ul, CURLOPT_HEADER, true);
           curl_setopt($ul, CURLOPT_NOBODY, true);
           curl_setopt($ul, CURLOPT_RETURNTRANSFER, true);
           $resp = curl_exec($ul);
           curl_close($ul);
           if ($resp)
         return "<span style='color: green; font-size: 14px; font-weight: bold;'>Site seems to be up and running!</span>";
           return "<span style='color: red; font-size: 14px; font-weight: bold;'>Oops nothing found, the site is either offline or the domain doesn't exist</span>";
   }




Usage
Download source  Code
   $resp = check_url("http://www.fangree.com");
   echo "<div class='resp'>".$resp."</div>";




http://www.fangree.com will give following message
Site seems to be up and running!

http://www.php-fangree.co.uk will give following message
Oops nothing found, the site is either offline or the domain doesn't exist

htp://www.php-fangree.co.uk will give following message
URL provided wasn't valid



I have this as a page on my site
http://www.dark-f..._check.php
Dark Fusion - PHP Fusion v7 Mods , Tutorials , Support
 
http://dark-fusion.se
spunk
Hey, nice function for weblinks.php Grin
 
http://www.bdsm-ansichten.com
Jump to Forum:
Similar Threads
Thread Forum Replies Last Post
There is an error with news and articles Locales Forum 6 17-06-2013 05:18
Php Fusion BR. Error creating table version translated into Portuguese in Brazil. Installation Issues 2 17-06-2013 05:16
Please Help. Please ! ERROR "Zero Sized Reply" Suspected Bugs and Errors 5 10-06-2013 06:52
Zero Sized Reply ERROR Suspected Bugs and Errors 2 10-06-2013 06:47
Step 6 error Installation Issues 3 28-05-2013 01:55
Official Home of PHP-Fusion uses cookies. Some may already have been set. Read more about our Cookies here.
Please click the button I Consent Cookies to hide this bar and accept our cookies. If you continue to use the site with no action taken, we'll assume that you consent our cookies anyway.
Cookiebar Panel byVenue