Page 1 of 1
Url Exist
Posted: Mon May 17, 2004 3:15 pm
by Spaz
Hey all im knew to this forum but wondering if you could help me. I need a snippet to help me with findin if a certain URL exists....
url_exists(); (i know that is not a function but is there n e thing like that you lot know off??)
Posted: Mon May 17, 2004 3:22 pm
by delorian
Try reading about regular expressions. You can find almost everything in The Manual

but please start with preg_* family ->
http://php.net/preg
Posted: Mon May 17, 2004 3:27 pm
by Spaz
ill take alook cheers.
Posted: Mon May 17, 2004 3:31 pm
by Spaz
It aint really what im looking for.. i need a bit off script so when i make a function, say, URL_exists("
www.php.net"); if return TRUE, something will happen, If return FALSE something will happen.
Posted: Mon May 17, 2004 3:42 pm
by feyd
if the url wrappers are setup for your file* functions.. is_file('
http://www.php.net')
may work.. file_get_contents('
http://www.php.net') would work..
Code: Select all
$exists = !!@file_get_contents('http://www.php.net');
Posted: Mon May 17, 2004 3:56 pm
by delorian
If your url wrappers are set off, you could use fsockopen() and send the following request:
Code: Select all
GET / HTTP/1.1\r\n
Host www.example.com\r\n\
Connection: close\r\n\r\n
But I can't tell that will do what you want,
Posted: Mon May 17, 2004 4:01 pm
by Spaz
Code: Select all
<?php
if($exists = !!file_get_contents('http://www.php.net')) {
echo $site.' is a site and can be found <a href="'.$site.'">HERE</a>';
}
else
{
echo "Site does not exsist";
}
?>
i get this when using that =
Warning: file_get_contents(): URL file-access is disabled in the server configuration in /home/spaz/www/index.php on line 6
Warning: file_get_contents(
http://www.php.net): failed to open stream: no suitable wrapper could be found in /home/spaz/www/index.php on line 6
Site does not exsist
Posted: Mon May 17, 2004 5:05 pm
by PrObLeM
if(!!file_get_contents('
http://www.php.net')) {
Posted: Tue May 18, 2004 1:15 am
by Spaz
na, still a no go. anyone else with n e ideas?
Posted: Tue May 18, 2004 1:17 am
by feyd
with URL file-access disabled.. you gotta use sockets like delorian suggested.
Posted: Tue May 18, 2004 12:08 pm
by Spaz
Code: Select all
<?php
if($search) {
$site_search = "www.".$site.".".$site2;
$URL = "http://";
$fp = fsockopen($site_search, 80, $errno, $errstr, 30)
if (!$fp) {
die("not avaialable");
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: ".$site_search."\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
echo '<center>'.$site_search.' is active and can be found <a href="'.$URL.$site_search.'">HERE</a></center>';
fclose($fp);
}
}
?>
<center>
<form action="index.php" method="post">
WWW.<input type="text" name="site">.<input type="text" name="site2" size="3">
<input type="submit" value="search" name="search">
</form>
</center>
this works if the web site is TRUE but if returns FALSE it errors out...you know n e way to handle the error? (
http://www.snowysworld.com)
Posted: Tue May 18, 2004 12:13 pm
by feyd
tossing an @ sign infront of fsockopen() will suppress the error.
Posted: Tue May 18, 2004 12:16 pm
by Spaz
what does the @ do. why and how?
Posted: Tue May 18, 2004 12:40 pm
by Spaz
Cheers all works perfectly
http://www.snowysworld.com
Posted: Tue May 18, 2004 2:10 pm
by feyd
Spaz wrote:what does the @ do. why and how?
feyd wrote:tossing an @ sign infront of fsockopen() will suppress the error.