David Nelson Posted April 20, 2008 Share Posted April 20, 2008 Hey, On my site there are a lot of php-generated links, and sometimes they are broken. I've seen it before, but I was wondering if someone could point me in the right direction of a script that you could define a link to and have it check to see if the page exists/resolves, then return a result either "Working" or "Down" to the user. Thanks everyone. Link to comment https://forums.phpfreaks.com/topic/102022-script-to-check-if-website-resolves-then-return-result/ Share on other sites More sharing options...
monkeypaw201 Posted April 20, 2008 Share Posted April 20, 2008 Well, you could go with the fopen() and if it returns a result it means the page is there.. Link to comment https://forums.phpfreaks.com/topic/102022-script-to-check-if-website-resolves-then-return-result/#findComment-522122 Share on other sites More sharing options...
GingerRobot Posted April 20, 2008 Share Posted April 20, 2008 You could use cURL and check the HTTP response code: <?php $url = 'http://www.google.co.uk'; $ch = curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE); curl_exec($ch); echo curl_getinfo($ch,CURLINFO_HTTP_CODE); ?> http://en.wikipedia.org/wiki/List_of_HTTP_status_codes Link to comment https://forums.phpfreaks.com/topic/102022-script-to-check-if-website-resolves-then-return-result/#findComment-522132 Share on other sites More sharing options...
David Nelson Posted April 20, 2008 Author Share Posted April 20, 2008 Okay Sweet! How would I return a result? I'm real new to PHP so I don't know how to take that code and make it return "Working" or "Down" based off of what it finds. Thanks for all your help guys. This forum rules! Link to comment https://forums.phpfreaks.com/topic/102022-script-to-check-if-website-resolves-then-return-result/#findComment-522136 Share on other sites More sharing options...
monkeypaw201 Posted April 20, 2008 Share Posted April 20, 2008 http://us.php.net/fopen Read up on it, post the code, and we'll fix it Link to comment https://forums.phpfreaks.com/topic/102022-script-to-check-if-website-resolves-then-return-result/#findComment-522139 Share on other sites More sharing options...
GingerRobot Posted April 20, 2008 Share Posted April 20, 2008 With my method: <?php function checkurl($url){ $ch = curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE); curl_setopt($ch,CURLOPT_FAILONERROR,TRUE); if(curl_exec($ch) !== FALSE){ return 'URL ok'; }else{ return 'Could not connect to site'; } } echo checkurl('http://www.google.co.uk'); echo '<br />'; echo checkurl('http://www.madeupurl.com'); ?> Link to comment https://forums.phpfreaks.com/topic/102022-script-to-check-if-website-resolves-then-return-result/#findComment-522144 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.