RE: [PHP] how to get http header in c extension
| From: | Tom Tom | Date: | Mon, 02 Nov 2015 10:41:48 +0000 |
| Subject: | RE: [PHP] how to get http header in c extension | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-325236@lists.php.net to get a copy of this message | ||
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