note 112652 added to function.get-headers

From: Date: Tue, 09 Jul 2013 14:47:57 +0000
Subject: note 112652 added to function.get-headers
Groups: php.notes 
Request: Send a blank email to php-notes+get-195546@lists.php.net to get a copy of this message
I know you're not supposed to reference other notes, but sincere props to Nick at Innovaweb's comment, for which I base this addition to his idea: If you use that function, it will return a string, which is great if you are checking for only files that return 404, or 200, or whatnot. If you cast the string value to an integer, you can perform mathematical comparison on it. For example: <?php function get_http_response_code($theURL) { $headers = get_headers($theURL); return substr($headers[0], 9, 3); } if(intval(get_http_response_code('filename.jpg')) < 400){ // File exists, huzzah! } ?> Rule of thumb is if the response is less than 400, then the file's there, even if it doesn't return 200. ---- Server IP: 69.147.83.199 Probable Submitter: 98.111.166.36 ---- Manual Page -- http://php.net/manual/en/function.get-headers.php Edit -- https://master.php.net/note/edit/112652 Del: integrated -- https://master.php.net/note/delete/112652/integrated Del: useless -- https://master.php.net/note/delete/112652/useless Del: bad code -- https://master.php.net/note/delete/112652/bad+code Del: spam -- https://master.php.net/note/delete/112652/spam Del: non-english -- https://master.php.net/note/delete/112652/non-english Del: in docs -- https://master.php.net/note/delete/112652/in+docs Del: other reasons-- https://master.php.net/note/delete/112652 Reject -- https://master.php.net/note/reject/112652 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195546) next »