-
-
Save dereknguyen269/5918d08a203f14608b3568a764bf15ab to your computer and use it in GitHub Desktop.
How To Check URL Is Working Or Not In Programing Languages?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url = "http://www.domain.com/demo.jpg"; | |
$curl = curl_init($url); | |
curl_setopt($curl, CURLOPT_NOBODY, true); | |
$result = curl_exec($curl); | |
if ($result !== false) | |
{ | |
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); | |
if ($statusCode == 404) | |
{ | |
echo "URL Not Exists" | |
} | |
else | |
{ | |
echo "URL Exists"; | |
} | |
} | |
else | |
{ | |
echo "URL not Exists"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url = "http://www.domain.com/demo.jpg"; | |
$headers = @get_headers($url); | |
if(strpos($headers[0],'404') === false) | |
{ | |
echo "URL Exists"; | |
} | |
else | |
{ | |
echo "URL Not Exists"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib2 import urlopen | |
code = urlopen("https://kipalog.com").code | |
if code == 200: | |
print "Exists!" | |
# Or | |
import urllib2 | |
ret = urllib2.urlopen('https://kipalog.com') | |
if ret.code == 200: | |
print "Exists!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'open-uri' | |
def working_url?(url_str) | |
url = URI.parse(url_str) | |
Net::HTTP.start(url.host, url.port) do |http| | |
http.head(url.request_uri).code == '200' | |
end | |
rescue | |
false | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
http_code=$(curl -I -s -o /dev/null -w "%{http_code}" "https://kipalog.com/") | |
if [ "$http_code" == "200" ]; then | |
echo "Exist!!!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment