RSS
You are here: Home » Ant's Highlights » Validating a website in PHP

Validating a website in PHP

Sat, Aug 23, 2008

Ant's Highlights, Internet, PHP

Validating a website in PHP

I found this pretty hard to begin with I was uncertain of how to check whether a website was online without writing a complicated string of Regular Express and even then this didn’t check if the site was active at that point in time. The solution was supprisingly simple:

We can use the PHP Function “fsockopen” to check that a the port is open on the appropriate hostname (website address).

$urlExists = @fsockopen($siteurl,80);

if($urlExists) {

// do something

} else {

// show an error

}

Simply pass in the Site URL Variable.

This post was written by:

Anthony - who has written 137 posts on Anthony Shapley.


Contact the author

Leave a Reply