Web lists-archives.com

RE: [PHP] how to get http header in c extension






Hi!
> hi all
> I want to get specific http header key-value in my c extension.
> How should I do ? Thanks

You can access HTTP header information via $_SERVER. Searchingthrough PHP's codebase for an example of this gave me:http://lxr.php.net/xref/PHP_7_0/ext/phar/phar_object.c#61
>From there, it's not too hard to see how to do it... For example:
HashTable *_SERVER;zval *data;
if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_UNDEF) {	return;}
_SERVER = Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]);
data = zend_hash_str_find(_SERVER, "CONTENT_TYPE", sizeof("CONTENT_TYPE")-1);
if (data == NULL) {	php_printf("Is not set...\n");} else {	php_printf("%s\n", Z_STRVAL_P(data));}
Regards,Tom