473,378 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how to validate a url

Hi,

Anyone can tell me how to validate
if a web page is online or 404 ?

Thanx

Yang

--
-------------------------------------------------------------------------
FIGHT BACK AGAINST SPAM!
Download Spam Inspector, the Award Winning Anti-Spam Filter
http://mail.giantcompany.com

Jul 16 '05 #1
5 8882
Erwin Moller <si******************************************@spam yourself.com> writes:
Yang Li Ke wrote:
Hi,

Anyone can tell me how to validate
if a web page is online or 404 ?


A portable an reliable method :

404 :
02/09 16:22 root@fusion ~# telnet localhost 80 Err 1 #16
#I send :
HEAD /does_not_exists.php HTTP/1.0

#I receive
HTTP/1.1 404 Not Found
Date: Tue, 02 Sep 2003 14:24:04 GMT
Server: Apache/1.3.26 (Unix) PHP/4.3.3 mod_ssl/2.8.10 OpenSSL/0.9.6g
Connection: close
Content-Type: text/html; charset=iso-8859-1

online :
#I send :
HEAD / HTTP/1.0

#Ireceive :
HTTP/1.1 200 OK
Date: Tue, 02 Sep 2003 14:25:03 GMT
Server: Apache/1.3.26 (Unix) PHP/4.3.3 mod_ssl/2.8.10 OpenSSL/0.9.6g
Content-Location: index.html.en
Vary: negotiate,accept-language,accept-charset
TCN: choice
Last-Modified: Wed, 29 Jan 2003 10:58:19 GMT
ETag: "381a2-a71-3e37b3cb;3f546ad9"
Accept-Ranges: bytes
Content-Length: 2673
Connection: close
Content-Type: text/html
Content-Language: en
Expires: Tue, 02 Sep 2003 14:25:03 GMT

So, You can easily use it with the help of fopen(), fputs(), etc....

Good luck.

--
Julien CROUZET

Jul 16 '05 #2
Yang Li Ke, still there??

What Julien suggested is maybe not working.
Here is a little script of my, and it does not output the headers.

Julien, do you know why I do not receive any headers this way??

---------------------------------
<?
$theurl = @$_POST["theurl"];
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>urltest</title>
</head>
<body>

Check any URL:
<form action="" method="POST" name="urlform">
<input type="hidden" name="getdata" value="Y">
<br>
<input type=text size=40 name="theurl" value="<? echo $theurl; ?>">
<br>
<input type="submit" value="haal data">
</form>

<?
if (isset($_POST["getdata"])) {
// okay get the url
// only works if track_errors = On is set in php.ini
$php_errormsg = "";
$handle = @fopen ($theurl, "r");
if ($php_errormsg != "") {
?>
Cannot open URL....
<?
} else
{

?>
<hr>
<b>The content of <i>$theurl</i>:</b>
<br>
$php_errormsg= <? echo $php_errormsg; ?>
<hr>
<pre>
<?
while (!feof ($handle)) {
$buffer = fgets($handle, 4096);
echo htmlentities($buffer);
}
fclose ($handle);
ECHO "</pre>";
}
}
?>

</body>
</html>

Jul 16 '05 #3
Erwin Moller <si******************************************@spam yourself.com> writes:
Yang Li Ke, still there??

What Julien suggested is maybe not working.
Here is a little script of my, and it does not output the headers.

Julien, do you know why I do not receive any headers this way??

---------------------------------
<?
$theurl = @$_POST["theurl"];
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>urltest</title>
</head>
<body>

Check any URL:
<form action="" method="POST" name="urlform">
<input type="hidden" name="getdata" value="Y">
<br>
<input type=text size=40 name="theurl" value="<? echo $theurl; ?>">
<br>
<input type="submit" value="haal data">
</form>

<?
if (isset($_POST["getdata"])) {
// okay get the url
// only works if track_errors = On is set in php.ini
$php_errormsg = "";
$handle = @fopen ($theurl, "r");
Here, you open the socket
if ($php_errormsg != "") {
?>
Cannot open URL....
<?
} else
{

?>
<hr>
<b>The content of <i>$theurl</i>:</b>
<br>
$php_errormsg= <? echo $php_errormsg; ?>
<hr>
<pre>
<?
while (!feof ($handle)) {
$buffer = fgets($handle, 4096);
here you read the socket till the server close the connection
echo htmlentities($buffer);
}
fclose ($handle);
ECHO "</pre>";
}
}
?>

</body>
</html>


You must send "HEAD /page.php HTTP/1.0\n\n" to have an answer.

And be careful of "while (!feof(" cause sometimes apache
doesn't close the connection after the answer, and wait for
another query during {x} seconds.

Close you socket once you received the status.

Good luck again =)

--
Julien CROUZET
Jul 16 '05 #4
"Yang Li Ke" <ya******@sympatico.ca> writes:
>$php_errormsg = "";
>$handle = @fopen ($theurl, "r");
>if ($php_errormsg != "") {


I dont really understand how will the $php_errormsg get a value if u dont
put any $php_errormsg = something;


"The previous error message: $php_errormsg
$php_errormsg is a variable containing the text of the last error
message generated by PHP. This variable will only be available within
the scope in which the error occurred, and only if the track_errors
configuration option is turned on (it defaults to off)."

It is a reserved variable.

--
Julien CROUZET

Jul 16 '05 #5
Thanks for explaining Julien.
:-)
Jul 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SHC | last post by:
Hi all, I have a VC++ .NET 2003 - Windows XP Pro PC. I created a Win32 console application in my VC++ .NET 2003 and copied validateDOM.cpp, books.xml and books.xsd (see the attached files below)...
5
by: Jim Heavey | last post by:
When should you use the Page.Validate() method? I thought you would use this method if you have some Server side validation (CustomControl's) you wanted to use and this would cause them to be...
11
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider...
0
by: Marc Scheuner | last post by:
Folks, I'm faced with a dilemma here - I have an XML document and for part of it, I have an XSD schema to validate it - but not for the rest of it. Can I still validate at least part of the...
4
by: Brybot | last post by:
I have a form that i've split up into multiple asp:panels, each panel has a number of validators which work correctly. At on the last panel, i want to commit the data collected to a database. I...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.