Url Exist

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Spaz
Forum Newbie
Posts: 10
Joined: Mon May 17, 2004 3:15 pm

Url Exist

Post 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??)
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post 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
Spaz
Forum Newbie
Posts: 10
Joined: Mon May 17, 2004 3:15 pm

Post by Spaz »

ill take alook cheers.
Spaz
Forum Newbie
Posts: 10
Joined: Mon May 17, 2004 3:15 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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');
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post 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,
Spaz
Forum Newbie
Posts: 10
Joined: Mon May 17, 2004 3:15 pm

Post by Spaz »

Code: Select all

<?php

if($exists = !!file_get_contents('http://www.php.net')) &#123;
	echo $site.' is a site and can be found <a href="'.$site.'">HERE</a>';
&#125;
else
&#123;
	echo "Site does not exsist";
&#125;
?>
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
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

if(!!file_get_contents('http://www.php.net')) {
Spaz
Forum Newbie
Posts: 10
Joined: Mon May 17, 2004 3:15 pm

Post by Spaz »

na, still a no go. anyone else with n e ideas?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

with URL file-access disabled.. you gotta use sockets like delorian suggested.
Spaz
Forum Newbie
Posts: 10
Joined: Mon May 17, 2004 3:15 pm

Post by Spaz »

Code: Select all

<?php
if($search) &#123;
$site_search = "www.".$site.".".$site2;
$URL = "http://";
$fp = fsockopen($site_search, 80, $errno, $errstr, 30)
if (!$fp) &#123;
   die("not avaialable");
&#125; else &#123;
   $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);
&#125;
&#125;
?> 
<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)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

tossing an @ sign infront of fsockopen() will suppress the error.
Spaz
Forum Newbie
Posts: 10
Joined: Mon May 17, 2004 3:15 pm

Post by Spaz »

what does the @ do. why and how?
Spaz
Forum Newbie
Posts: 10
Joined: Mon May 17, 2004 3:15 pm

Post by Spaz »

Cheers all works perfectly http://www.snowysworld.com
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Spaz wrote:what does the @ do. why and how?
feyd wrote:tossing an @ sign infront of fsockopen() will suppress the error.
Post Reply