How can I check if an url exists in laravel 5.1?
For example, I want to check if www.google.com
exists.
$url ="www.google.com";
if(exists(url)){
// do something
}
What function or code can I use to return true for the above example?
How can I check if an url exists in laravel 5.1?
For example, I want to check if www.google.com
exists.
$url ="www.google.com";
if(exists(url)){
// do something
}
What function or code can I use to return true for the above example?
In Laravel you can use use GuzzleHttp\Client
as such:
use GuzzleHttp\Client;
$client = new Client();
$request = $client->head('http://google.com/');
if( $request->getStatusCode() == 200 ) {
// Do something ...
}
You can use normal PHP code in laravel.
Use get_headers()
function, it returns false if the given domain is not registered.
$url = 'http://google.com/';
if(get_headers($url))
// do something
And don't forget the HTTP (http://) protocol prepending the domain.