Forum Replies Created
Viewing 1 post (of 1 total)
-
AuthorPosts
-
December 18, 2019 at 4:16 pm in reply to: Notice: Undefined variable: http_response_header in function-set-avia-frontend #1167342
This issue persists (2019-12-18, Enfold v4.6.3.1).
allow_url_fopen = 0 is a good security setting in a shared environment (notice: it also disables get_headers(), so if one is not available – so is the other!). I have a better fix for this situation, since all you really need to know is whether the remote URL exists or not:
if(!function_exists('avia_is_200')) { function avia_is_200($url) { if ( ini_get('allow_url_fopen') ) return __avia_is_200_helper_fopen($url); else if ( function_exists("curl_init") ) return __avia_is_200_helper_curl($url); else return false; } function __avia_is_200_helper_fopen($url) { $options['http'] = array( 'method' => "HEAD", 'ignore_errors' => 1, 'max_redirects' => 0 ); $body = @file_get_contents($url, null, stream_context_create($options), 0, 1); sscanf($http_response_header[0], 'HTTP/%*d.%*d %d', $code); return $code === 200; } function __avia_is_200_helper_curl($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // security isn't an issue in this case, and you can skip maintaining the root CA .pem required for this curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $code === 200; } }
- This reply was modified 5 years ago by ellmann_creative.
-
AuthorPosts
Viewing 1 post (of 1 total)