Url Exist
Moderator: General Moderators
Url Exist
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??)
url_exists(); (i know that is not a function but is there n e thing like that you lot know off??)
Try reading about regular expressions. You can find almost everything in The Manual
but please start with preg_* family -> http://php.net/preg
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.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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');If your url wrappers are set off, you could use fsockopen() and send the following request:
But I can't tell that will do what you want,
Code: Select all
GET / HTTP/1.1\r\n
Host www.example.com\r\n\
Connection: close\r\n\r\nCode: 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";
}
?>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
if(!!file_get_contents('http://www.php.net')) {
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)
Cheers all works perfectly http://www.snowysworld.com