How to check url exits or not in PHP


How to check file exist in given URL – PHP.

FOr check url exist or not you have to use below function for it.

you can also check for xml path exits or not.


	$url = "www.hariomrubber.com/sitemap.xml";
	
	if($this->is_url_exist($url))
	{
		echo "URL is exists";
	}else{
		echo "URL is not exists";
	}

	function is_url_exist($url)
	{
		$ch = curl_init($url);    
		curl_setopt($ch, CURLOPT_NOBODY, true);
		curl_exec($ch);
		$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	
		if($code == 200){
			$status = true;
		}else{
			$status = false;
		}
		curl_close($ch);
		return $status;
	}
	

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s