Jump to content

check if a url address has a page with content


Recommended Posts

I made a piece of code to check wheter a url page exists.

This is a part of the get_headers routine I'm using:

			 // check with checkdnsrr
			 // validate with FILTER_VALIDATE_URL
			 // get_headers part
				$array = get_headers($url);

				$string = $array[0];
				if( strpos($string,"200") || strpos($string,"301") || strpos($string,"302") || strpos($string,"403")   ) {

											else {
												echo '<br><br> this site is insecure<br>';
										 echo '<br> use http instead of https <br><br>';




The problem is that some websites configure their server either http or https but this does not mean that there is page content.

What can be used to determine if there is an index.php or an index.html or any alternative indexpage used?

The things I'm considering are: file_exists, file_get_contents or glob() on the other hand var_dump($array) gives in several cases the parameter: Content Type. The value is txt/html . Can this be used to see if there is a page?

What would you recommend and can you give an example how this is used?






Link to comment
Share on other sites

The error is like this:

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 unrecognized name in .....

it concerns the line with:

$array = get_headers($url);


the url input is:

if I change htttps to http then I dont have any error messages.

I would like to find a way to check in advance what kind of url is put in to avoid the error messages.

Anyone got any idea?




Link to comment
Share on other sites

You can use parse_url to break up the URL, and then check the protocol to see if it's https or not.  

If you want to skip the certificate validation which is causing that error, you can do that also:


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...