Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2023 - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Does a URL exist?
HTML Web Page Data Handling example from a Well House Consultants training course
More on HTML Web Page Data Handling [link]

If you're searching for a page where you can view this page, select here

This example references the following resources:

Source code: urlex.html Module: H110
<html><head><title>Does a URL exist?</title></head>
<body bgcolor="white"><table width="600"><tr><td>
<h1>Does a particular URL exist?</h1>
A difficult question and one there isn't a general answer to - but
you can check whether an http:// URL is readable which is often the
question that's being asked. With a URL such as a mailto:, the only
way to check whether it exists is to send an email to it and see if
you get an answer back from the address owner.   You also need to
take care with testing like this to ensure that the user can't
enter local file URLs on your server and use it to check the
existence (or otherwise) of files / directories .... <br /><br />
Checking URL <b>http://www.wellho.net/net/new.html</b><br />This URL s readable<br />
<hr />
Please enter a URL you would like to validate (existence check):
<form>The URL: <input name="url" /> and <input type="submit" /></form>
<br /><i>Note - in order to save myself the need to monitor the use of this script, I
have only loaded it here it its tested (HTML) form and the form just above will
not work.   You are welcome AT YOUR OWN RISK to test the code that's presented
below on your own server. Unless you are very sure of what you are doing, I advise
you NOT to put this script onto a live Internet server</i>
<hr />
Copyright <a href="http://www.wellho.net/">Well House Consultants</a>
2005<br /><br />
<b>Source code of this example:</b><br /><br />
<code><font color="#000000">
<font color="#0000BB">&lt;?php<br /><br /></font><font color="#007700">if (</font><font color="#0000BB">$_REQUEST</font><font color="#007700">[</font><font color="#0000BB">url</font><font color="#007700">] != </font><font color="#DD0000">""</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">1</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;if (! </font><font color="#0000BB">ereg</font><font color="#007700">(</font><font color="#DD0000">"^https?://"</font><font color="#007700">,</font><font color="#0000BB">$_REQUEST</font><font color="#007700">[</font><font color="#0000BB">url</font><font color="#007700">])) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$status </font><font color="#007700">= </font><font color="#DD0000">"This demo requires a fully qualified http:// URL"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;} else {<br />&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (@</font><font color="#0000BB">fopen</font><font color="#007700">(</font><font color="#0000BB">$_REQUEST</font><font color="#007700">[</font><font color="#0000BB">url</font><font color="#007700">],</font><font color="#DD0000">"r"</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$status </font><font color="#007700">= </font><font color="#DD0000">"This URL s readable"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$status </font><font color="#007700">= </font><font color="#DD0000">"This URL is not readable"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">0<
/font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$status </font><font color="#007700">= </font><font color="#DD0000">"no URL entered (yet)"</font><font color="#007700">;<br />}<br /><br /></font><font color="#0000BB">?&gt;<br /></font>&lt;html&gt;&lt;head&gt;&lt;title&gt;Does a URL exist?&lt;/title&gt;&lt;/head&gt;<br />&lt;body bgcolor="white"&gt;&lt;table width="600"&gt;&lt;tr&gt;&lt;td&gt;<br />&lt;h1&gt;Does a particular URL exist?&lt;/h1&gt;<br />A difficult question and one there isn't a general answer to - but<br />you can check whether an http:// URL is readable which is often the<br />question that's being asked. With a URL such as a mailto:, the only<br />way to check whether it exists is to send an email to it and see if<br />you get an answer back from the address owner.&nbsp;&nbsp;&nbsp;You also need to <br />take care with testing like this to ensure that the user can't<br />enter local file URLs on your server and use it to check the<br />existence (or ot
herwise) of files / directories .... &lt;br /&gt;&lt;br /&gt;<br /><font color="#0000BB">&lt;?php<br /></font><font color="#007700">if (</font><font color="#0000BB">$result </font><font color="#007700">!= </font><font color="#0000BB">0</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;print </font><font color="#DD0000">"Checking URL &lt;b&gt;"</font><font color="#007700">.</font><font color="#0000BB">htmlspecialchars</font><font color="#007700">(</font><font color="#0000BB">$_REQUEST</font><font color="#007700">[</font><font color="#0000BB">url</font><font color="#007700">]).</font><font color="#DD0000">"&lt;/b&gt;&lt;br /&gt;"</font><font color="#007700">;<br />}<br />print </font><font color="#DD0000">"$status"</font><font color="#007700">;<br /></font><font color="#0000BB">?&gt;<br /></font>&lt;br /&gt;<br />&lt;hr /&gt;<br />Please enter a URL you would like to validate (existence check):<br />&lt;form&gt;The URL: &lt;input name="url" /&gt; and &lt;input type="submit" /&gt;&lt;/form&gt;<br />&lt;hr
/&gt;<br />Copyright &lt;a href="http://www.wellho.net/"&gt;Well House Consultants&lt;/a&gt;<br /><font color="#0000BB">&lt;?= date</font><font color="#007700">(</font><font color="#DD0000">"Y"</font><font color="#007700">) </font><font color="#0000BB">?&gt;</font>&lt;br /&gt;&lt;br /&gt;<br />&lt;b&gt;Source code of this example:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;<br /><font color="#0000BB">&lt;?= highlight_file</font><font color="#007700">(</font><font color="#0000BB">$_SERVER</font><font color="#007700">[</font><font color="#0000BB">SCRIPT_FILENAME</font><font color="#007700">],</font><font color="#0000BB">1</font><font color="#007700">) </font><font color="#0000BB">?&gt;<br /></font>&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;<br />&lt;/body&gt;&lt;/html&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br /></font>

Learn about this subject

This example is covered on the following public courses:
 * Learning to program in PHP
 * PHP Programming
 * Beginning PHP - weekend course / hobby / club / leisure users
 * PHP Programming
 * Learning to program in PHP
and is fully described on the course or in your printed course manual

Books covering this topic
Yes. We have over 700 books in our library. Books covering PHP are listed here and when you've selected a relevant book we'll link you on to Amazon to order.

Other Examples
This example comes from our "HTML Web Page Data Handling" training module. You'll find a description of the topic and some other closely related examples on the "HTML Web Page Data Handling" module index page.

Full description of the source code
You can learn more about this example on the training courses listed on this page, on which you'll be given a full set of training notes.

Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License.

Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre.
The Horse's mouth provides a daily tip or thought.
• Further resources are available via the resources centre.
• All of these resources can be searched through through our search engine
• And there's a global index here.

Purpose of this website
This is a sample program, class demonstration or answer from a training course. It's main purpose is to provide an after-course service to customers who have attended our public private or on site courses, but the examples are made generally available under conditions described below.

Web site author
This web site is written and maintained by Well House Consultants.

Conditions of use
Past attendees on our training courses are welcome to use individual examples in the course of their programming, but must check the examples they use to ensure that they are suitable for their job. Remember that some of our examples show you how not to do things - check in your notes. Well House Consultants take no responsibility for the suitability of these example programs to customer's needs.

This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details.

Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2023: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/ex.php • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb