Best way to access $_SERVER variables from c?
| From: | Glenn Richmond | Date: | Tue, 21 Nov 2006 01:32:39 +0000 |
| Subject: | Best way to access $_SERVER variables from c? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-26689@lists.php.net to get a copy of this message | ||
Hi All,
I apologize if this is an extremely straight-forward question, but I'm
trying to access the SERVER_NAME variable from PHP source (a tweak to
protect against accessing disallowed directory paths in a shared
environment without enabling safe mode). I've got the following code:
if
(zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht,
"SERVER_NAME", sizeof("SERVER_NAME"), (void **) &server_name) !=
FAILURE) {
// Got server name
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Base directory:
%s, %s, %s", basedir, path, server_name);
return 0;
} else {
// Unable to find server name
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find
server_name hash.");
return 0;
}
However, the value that is reported as SERVER_NAME appears to be
giberish (the call succeeds, but the value doesn't make sense). I'm
getting "lEÊ·èEÊ·EÊ·" for the value of the server name. Any idea what
is going on here? I've also tried the get_env function without success,
but I'm guessing this is only valid when running as a CGI script as
opposed to mod_php5.
Note that I'm just using the php_error_docref as debugging output at
this point.
Regards,
Glenn.