Page 1 of 1

[SOLVED] check valid URL

Posted: Tue Apr 04, 2006 8:00 am
by malcolmboston
i have been trying to check if a given URL to my class is valid or not

im not looking for ereg, im looking for the script to go to the site and tell me if its valid or not, basically ive been trying to use various system tools such as nslookup to achieve this, all without luck

Is there any bullet-proof methods of doing this?

Thanks
Mal

Posted: Tue Apr 04, 2006 8:25 am
by Chris Corbyn
fsockopen() ? along with a GET request. check the headers for 404 response ;)

Posted: Tue Apr 04, 2006 10:26 am
by malcolmboston
the following code

Code: Select all

$fp = fsockopen($this->URL, 80, $errno, $errstr, 30);
gives me
PHP wrote: Warning: fsockopen(): unable to connect to http://www.evolution-interactive.co.uk:80 in /home/discwo/public_html/linkchecker.class.php on line 17
when i do a var_dump of the class i get

Code: Select all

object(linkchecker)(3) {
  ["URL"]=>
  string(38) "http://www.evolution-interactive.co.uk"
  ["errno"]=>
  int(13)
  ["errstr"]=>
  string(17) "Permission denied"
}
whats this mean?

Posted: Tue Apr 04, 2006 10:35 am
by feyd
try without the http:// bit.

Posted: Tue Apr 04, 2006 10:46 am
by malcolmboston
ok, did that, works to an extent anyway, now i get
results wrote: HTTP/1.1 200 OK Date: Tue, 04 Apr 2006 15:45:05 GMT Server: Last-Modified: Mon, 28 Feb 2005 10:01:46 GMT ETag: "760128-b9d-4222ec0a" Accept-Ranges: bytes Content-Length: 2973 Connection: close Content-Type: text/html
cPanel
There is no website configured at this address.


You are seeing this page because there is nothing configured for the site you have requested. If you think you are seeing this page in error, please contact the site administrator or datacenter responsible for this site.
erm, yes there is a website configured at that address....

any ideas?

Posted: Tue Apr 04, 2006 10:57 am
by malcolmboston
NvM
if you basically do

Code: Select all

$fp = fsockopen($this->URL, 80, $errno, $errstr, 30);
and then check if $fp has failed or not, then that will give you the correct answer from what ive tested so far

Posted: Tue Apr 04, 2006 11:04 am
by feyd

Code: Select all

[feyd@home]>php -r "$fp = fsockopen('www.evolution-interactive.co.uk',80,$errno,$errstr,30); if($fp){ fputs($fp, 'GET / HTTP/1.0'.PHP_EOL.'Host: www.evolution-interactive.co.uk'.PHP_EOL.PHP_EOL); do{ $str = fread($fp, 512); echo $str; }while(strlen($str));}"
HTTP/1.1 200 OK
Date: Tue, 04 Apr 2006 16:03:33 GMT
Server:
X-Powered-By: PHP/4.4.1
Connection: close
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="keywords" content="web design, CSS designs, web programming,PHP programming,online shop, promotion, listings, ranking, online shopping, templates, web hosting, ecommerce site, template, email service">
<meta name="description" content="Evolution Interactive are an web-design & web programming company specialising in PHP / MySQL developments, CSS based layouts and Search Enging Optimisation.">
<title>Evolution Interactive :: Evolve With Us</title>
<link href="css/silver.css" rel="stylesheet" type="text/css">
<script type="text/JavaScript">
<!--

function MM_swapImgRestore() { //v3.0
        var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
        var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
                d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
                if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
                for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
                if(!x && d.getElementById) x=d.getElementById(n); return x;
}

:snip: