Jump to content

vérifier un lien php


Recommended Posts

voici une fonction qui permet de vérifier des liens seulement elle ne marche pas elle me met tous le temps que le lien est valide ou bien il me met une erreur :

Notice: Undefined index: port in c:\////\check.php on line 54

<lien>http://www.hotmaifgl.com</lien> file exists!

<?php
function url_validate( $link )
{
$url_parts = @parse_url( $link );

if ( empty( $url_parts["host"] ) ) return( false );

if ( !empty( $url_parts["path"] ) )
{
$documentpath = $url_parts["path"];
}
else
{
$documentpath = "/";
}

if ( !empty( $url_parts["query"] ) )
{
$documentpath .= "?" . $url_parts["query"];
}

$host = $url_parts["host"];
$port = $url_parts["port"];


if (empty( $port ) ) $port = "80";
$socket = @fsockopen( $host, $port, $errno, $errstr, 30 );
if (!$socket)
{
return(false);
}
else
{
fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n");
$http_response = fgets( $socket, 22 );

if ( ereg("200 OK", $http_response, $regs ) )
{
return(true);
fclose( $socket );
} else
{
return(false);
}
}
}

$link = "http://www.hotmaifgl.com";
if (url_validate( $link )==false)
{ print ($link . " file exists!"); }
else
{ print ($link . " file doesn't exist!"); }
?>

que faire ??? Connaissez vous un script qui check les urls et qui soit fillable ( prenant en charge les erreurs ) ??

merci beaucoup d'avance

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...