By blinkingtwelve on
I need to find out if a given URL (specifically, the current URL) is accessible (ie returns HTTP 2xx/3xx) to a user (specifically, the anonymous user).
Thing is, the URLs are not always nodes, otherwise I might use the node_access API function. So at the moment I'm doing something like this, with curl:
function is_403(){
global $base_url;
$url = url($base_url.request_uri());
$ch = curl_init($url);
curl_setopt_array($ch, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_NOBODY => true));
if ((curl_exec($ch) != 0)
|| (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 403)) $denied = TRUE;
curl_close($ch);
return $denied;
}
So I'm using curl to let PHP make a request for me, for which I then read the HTTP status code. This works fine, but just doesn't seem right.
How could I do this from within Drupal, without making a separate HTTP request?
Comments
not possible
I guess this kind of introspection is not possible then...