简体   繁体   English

如何在php扩展名中获取请求标头

[英]how to get request headers in php extensions

i want to get request headers in php extension ,but use &SG(sapi_headers).headers seem to be get respond headers in php extension 我想在php扩展名中获取请求标头,但使用&SG(sapi_headers).headers似乎是在php扩展名中获取响应标头

i try to use as 我尝试用作

 static void agent_get_all_headers(){
         zend_llist_position pos;
         sapi_header_struct* h;

    for (h = (sapi_header_struct*)zend_llist_get_first_ex(&SG(sapi_headers).headers, &pos);h;h = (sapi_header_struct*)zend_llist_get_next_ex(&SG(sapi_headers).headers, &pos))
    {
         php_printf("SAPI! %.*s <br/>", h->header_len, h->header);
    }
 }

but it does not work 但这不起作用

i use code 我使用代码

char *get_http_request_uri(){
  char *returnstr="";
  zval *tmp_name;
  if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY || zend_is_auto_global_str(ZEND_STRL("_SERVER"))) &&
             (tmp_name = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "REQUEST_URI", sizeof("REQUEST_URI")-1)) != NULL &&
             Z_TYPE_P(tmp_name) == IS_STRING) {
             returnstr = join3(returnstr,Z_STRVAL_P(tmp_name));
 }
 return returnstr;}

to get REQUEST_URI in php extensions, but how to get a custom header in request? 在PHP扩展中获取REQUEST_URI,但是如何在请求中获取自定义标头?

Here am getting the HTTP header host and their value.we can follow the same to read custom header. 这是获取HTTP标头主机及其值的方法。我们可以按照相同的方法读取自定义标头。

string Getheader()
    {
        string attribute="HTTP_HOST";
        HashTable *server;
    if (zend_hash_find(&EG(symbol_table), "_SERVER", 8, (void **)&arr) == FAILURE)
        {
            return L"";
        }
        server = Z_ARRVAL_PP(arr);

        zval **val;
        string temp = "";
        if (zend_hash_find(server, attribute.c_str(), strlen(attribute.c_str()) + 1, (void **)&val) != FAILURE && Z_TYPE_PP(val) == IS_STRING)
        {
            if (attribute != "HTTP_HOST")
                temp.append("#~#");
            temp.append("host");
            temp.append("=");
            temp.append(Z_STRVAL_PP(val));

        }
        return temp;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM