Page 1 of 1

verify webpage

Posted: Mon Jun 27, 2011 3:23 pm
by danwguy
I have an input field that has verification of correct url, but I would also like it to check to make sure that the site is online. what I have currently is very simple...

Code: Select all

function isURL() {
 var url = document.getElementById("webpage_url");
 var urlerr = document.getElementById("url_error");
 var reg = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
 if(!reg.test(url.value)) {
 	urlerr.innerHTML = "Invalid WebPage Address";
 	url.focus();
 	} else {
 		urlerr.innerHTML = "<img src='custom/modules/CT221_SEP_test/js/images/good.png' style='margin-left: 140px; margin-top: -35px;' />";
 		}
 }
YAHOO.util.Event.on("webpage_url", "blur", isURL);
but like I said, I would like to add that when the blur function is called it will check to make sure that the link in the input box is a valid page and not returning a 404 error or something like that. Any ideas or help would be greatly appreciated. Thank you in advance.

Re: verify webpage

Posted: Mon Jun 27, 2011 5:13 pm
by superdezign
Due to cross-browsers issues with AJAX, I'd say the best way to do this is to build a middle-man script that would make the page request using cURL, check the headers, and return a JSON/XML/whatever-the-hell-you-want response

If you don't actually care about the headers and just want to check if the server is up, you could just make a system call to "ping" using shell_exec(). You can't do this in safe mode, though (which is enabled on most shared servers).

Re: verify webpage

Posted: Mon Jun 27, 2011 6:38 pm
by danwguy
Ya the only thing I care about is if it reports a 404 or a redirect, and not even really so much of a redirect, mainly just a 404. Any chance you could shoot me a quick example, i am completely new to this sort of thing. i usually code light javascript and php. Thank you.