GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   PHP Question (https://gfy.com/showthread.php?t=244401)

alex79 02-28-2004 10:58 AM

PHP Question
 
i want open an web addresse using the php function $x=file($url) ..
here is the problem: if the $url address don't exist then i get an Warning error: "php_network_getaddresses: getaddrinfo failed"
in a such case i don't want the warning error to be displayed.. i just want to display a message like "can't access url"

i've tryed next code:
$x=file($siteurl) or die("Can't access $url");
but first i get the warning error and after that my message...

anybody have an ideea how can i make to display just my message in the case that the $url don't exist?

JDog 02-28-2004 11:01 AM

if(!$x = fopen($url)) {
echo "Can not access $url";
exit;
}

Try that! :winkwink: :thumbsup

jDOG

alex79 02-28-2004 11:08 AM

Quote:

Originally posted by JDog
if(!$x = fopen($url)) {
echo "Can not access $url";
exit;
}


with this i get next:

Warning: Wrong parameter count for fopen() in /home/****** on line 23
Can not access http://www.********

swedguy 02-28-2004 11:23 AM

Quote:

Originally posted by alex79


with this i get next:

Warning: Wrong parameter count for fopen() in /home/****** on line 23
Can not access http://www.********

resource fopen ( string filename, string mode [, int use_include_path [, resource zcontext]])

fopen($url, "r") would be the correct syntax.

JDog 02-28-2004 11:24 AM

Quote:

Originally posted by swedguy


resource fopen ( string filename, string mode [, int use_include_path [, resource zcontext]])

fopen($url, "r") would be the correct syntax.

This is correct, I forgot the permission argument!

jDOG

Ash@phpFX 02-28-2004 11:38 AM

$fd=fopen("http://www.url.com","r");
while ($line=fgets($fd,1000))
{
$alltext.=$line;
}
fclose ($fd);

reads it into $alltext

alex79 02-28-2004 11:40 AM

Quote:


fopen($url, "r") would be the correct syntax.

still get the same warning error like first time:

Warning: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/*********
Warning: fopen("http://www.aaaa.aa", "r") - Bad file descriptor in /home/*************
Can not access http://www.aaaa.aa

:) how can i escape of this warning errors?

swedguy 02-28-2004 11:45 AM

If you only wanna suppress the PHP error messages (which is good on a live website). Add this to the top of your page:

ini_set("display_errors", 0);

alex79 02-28-2004 11:45 AM

Quote:

Originally posted by asher
$fd=fopen("http://www.url.com","r");
while ($line=fgets($fd,1000))
{
$alltext.=$line;
}
fclose ($fd);

reads it into $alltext

thanks but i get same errors with this code.. the problem is not that i can't read the file.. if the $url is correct and exist then i can read him withot problems with file() or fopen().... the problem is that when the $url don't exist then u get these warning errors displayed.. in a such case i just want to be displayed my eror text without warnings

swedguy 02-28-2004 11:45 AM

...or add an @ in front of the fopen()

Ash@phpFX 02-28-2004 11:49 AM

preceed the function with an @
that will stop the warnings
like @fopen()

swedguy 02-28-2004 11:49 AM

What it will look like:

$x = @file($siteurl);

if ($x) {
.....
} else {
print "Could not connect to $url";
exit;
}

alex79 02-28-2004 12:10 PM

ok.. @file() works fine.. thanks to everybody


All times are GMT -7. The time now is 06:07 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123