« July 2009 | Main | September 2009 »

August 06, 2009

Ajax URL Checker

The JS goes like this:

function check_url(me_url){

	$('url_message').innerHTML = '';

	var url_match = /https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/;

	if(url_match.test(me_url)){ poppy('URL is well-formed.'); $('url_warning').style.display = "none"; }
	
	else{ poppy('The URL entered appears to be invalid. Please ensure it begins with http:// or https://!'); $('url_warning').style.display = 'block'; return false; }

	$('url_message').style.display = 'inline';

	$('url_message').innerHTML = ' <strong style="text-decoration: blink;">Checking Link..</strong>';

    var da_url  = 'check_url.php';
    var params = '?url=' + me_url;
    var myAjax = new Ajax.Request(
                        da_url,
                        {
                                method: 'get',
                                parameters: params,
                                onComplete: success
                        });
						
		function success(this_request){
		
			try{ 
			
				var reply = this_request.responseText.evalJSON(true);  
				
				if(reply['status_code']){ 
				
					if( reply['status_code'] < 400){ $('url_message').innerHTML = ' <strong style="color: green">Link OK: Code ' + reply['status_code']+ '</strong>'; }
				
					else{ $('url_message').innerHTML = ' <strong style="color: red">Broken: Code ' + reply['status_code'] + '</strong>'; }
					
					} else { $('url_message').innerHTML = ' <strong style="color: red">No Such Site.</strong>'; }
				
				} catch(e){ blah = ''; }
		
			}	

	}

The PHP goes like this:

<?

require_once "HTTP/Request.php";

$req =& new HTTP_Request($_REQUEST['url']);

$response = $req->sendRequest();

header('Status:'.$req->getResponseCode());

print json_encode(array("status_code" => $req->getResponseCode()));

?>

Posted by pj at 01:15 PM | Comments (0)

August 04, 2009

New Chuck Stuff

RELEASE INFO - Cooking Vinyl UK

Posted by pj at 11:27 PM | Comments (0)