How on the PHP side to verify the correctness of the website URL?

I searched our SO questions, but the solutions found are based on calling the ping command executed using the PHP system function.

My web host server does not allow me to do this. What should I do?

Please help us.

Update

I need to check from server side .

+4
source share
2 answers

If by a valid URL you mean something that is not 404, then you can use get_headers() and look for 404 in the first returned element of the array.

 $url = 'http://google.com'; list($status) = get_headers($url); if (strpos($status, '404') !== FALSE) { // URL is 404ing } 

Alternatively, you can look for 200 , which would be a normal happy request :)

+11
source

try the following:

 //checking if the site exists by fopen, instead of file_get_contents to speed it up $url = "URL"; //your url goes in this place instead of nabtron.com if (@fopen($url,"r")) { echo "<b>".$url."</b> is accessible<br />"; } 
+3
source

All Articles