Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Navigation
Latest Addons
AD Gallery 51
SyntaxHighlighte... 51
Newsletters v4.03 112
Facebook Like Box 125
Newsletters v4.02 57
Metro 164
Facebook Connect 170
Shoutbox Panel 126
Redactor for PHP... 106
MI Floating Side... 109
Facebook Login/R... 154
Avatar Studio v2.03 179
Relationship Sta... 98
Sexual Orientati... 116
Fisherman 143
Popular Addons
iTheme2 5801
Arise 5790
User Control v1.23 4619
Event Calendar 4050
Photowidget panel 3888
Radio-Theme red2... 3356
Highslide Gallery 3313
CSS/JavaScript D... 3229
Facebook Connect... 2985
Dynamic Menu 2893
Slideshow Lightb... 2721
L-AMANT 2659
Enigma 2635
2Dark 2606
Black 2578
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?
www.8.php-fusion.net/images/smiley/fusion.png Coordinator of the Development of PHP-Fusion 8 www.8.php-fusion.net/images/smiley/fusion.png
Community Moderation Management & Support Team Leader
Owner of: www.php-fusion.se | www.php-fusion.net | www.php-fusion.us | www.php-fusion.mobi
 
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
HighSlide Gallery Error Panels and Infusions 1 17-05-2013 21:58
Need help with SQL Syntax error after update Upgrading issues 8 17-05-2013 09:13
Error after editing profile Panels and Infusions 8 21-04-2013 19:21
Shoutbox Error Suspected Bugs and Errors 3 19-04-2013 12:22
Forum error Suspected Bugs and Errors 2 19-04-2013 12:22
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