Jump to content

check if a url address has a page with content


Balderick

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:

			<?php 
			 
			 // check with checkdnsrr
			 // validate with FILTER_VALIDATE_URL
			 
			 ///////////////////////////////////////////////////
			 
			 // get_headers part
						
				$array = get_headers($url);
				
				var_dump($array);

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

				   
											} 
											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

If you get a 301 or 302 response, check the Location header in the array and make another get_headers() call to that URL to see if it exists.

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

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...