📄 php_apache.c
字号:
r = ((request_rec *) SG(server_context)); SECTION("HTTP Headers Information"); php_info_print_table_start(); php_info_print_table_colspan_header(2, "HTTP Request Headers"); php_info_print_table_row(2, "HTTP Request", r->the_request); env_arr = table_elts(r->headers_in); env = (table_entry *)env_arr->elts; for (i = 0; i < env_arr->nelts; ++i) { if (env[i].key && (!PG(safe_mode) || (PG(safe_mode) && strncasecmp(env[i].key, "authorization", 13)))) { php_info_print_table_row(2, env[i].key, env[i].val); } } php_info_print_table_colspan_header(2, "HTTP Response Headers"); env_arr = table_elts(r->headers_out); env = (table_entry *)env_arr->elts; for(i = 0; i < env_arr->nelts; ++i) { if (env[i].key) { php_info_print_table_row(2, env[i].key, env[i].val); } } php_info_print_table_end(); }}/* }}} *//* {{{ proto bool virtual(string filename) Perform an Apache sub-request *//* This function is equivalent to <!--#include virtual...--> * in mod_include. It does an Apache sub-request. It is useful * for including CGI scripts or .shtml files, or anything else * that you'd parse through Apache (for .phtml files, you'd probably * want to use <?Include>. This only works when PHP is compiled * as an Apache module, since it uses the Apache API for doing * sub requests. */PHP_FUNCTION(virtual){ pval **filename; request_rec *rr = NULL; if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(filename); if (!(rr = sub_req_lookup_uri ((*filename)->value.str.val, ((request_rec *) SG(server_context))))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", (*filename)->value.str.val); if (rr) destroy_sub_req (rr); RETURN_FALSE; } if (rr->status != 200) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", (*filename)->value.str.val); if (rr) destroy_sub_req (rr); RETURN_FALSE; } php_end_ob_buffers(1 TSRMLS_CC); php_header(); if (run_sub_req(rr)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", (*filename)->value.str.val); if (rr) destroy_sub_req (rr); RETURN_FALSE; } else { if (rr) destroy_sub_req (rr); RETURN_TRUE; }}/* }}} *//* {{{ proto array getallheaders(void) Alias for apache_request_headers() *//* }}} *//* {{{ proto array apache_request_headers(void) Fetch all HTTP request headers */PHP_FUNCTION(apache_request_headers){ array_header *env_arr; table_entry *tenv; int i; if (array_init(return_value) == FAILURE) { RETURN_FALSE; } env_arr = table_elts(((request_rec *) SG(server_context))->headers_in); tenv = (table_entry *)env_arr->elts; for (i = 0; i < env_arr->nelts; ++i) { if (!tenv[i].key || (PG(safe_mode) && !strncasecmp(tenv[i].key, "authorization", 13))) { continue; } if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) { RETURN_FALSE; } }}/* }}} *//* {{{ proto array apache_response_headers(void) Fetch all HTTP response headers */PHP_FUNCTION(apache_response_headers){ array_header *env_arr; table_entry *tenv; int i; if (array_init(return_value) == FAILURE) { RETURN_FALSE; } env_arr = table_elts(((request_rec *) SG(server_context))->headers_out); tenv = (table_entry *)env_arr->elts; for (i = 0; i < env_arr->nelts; ++i) { if (!tenv[i].key) continue; if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) { RETURN_FALSE; } }}/* }}} *//* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top]) Set an Apache subprocess_env variable */PHP_FUNCTION(apache_setenv){ int var_len, val_len, top=0; char *var = NULL, *val = NULL; request_rec *r = (request_rec *) SG(server_context); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) { RETURN_FALSE; } while(top) { if(r->prev) r = r->prev; else break; } ap_table_setn(r->subprocess_env, ap_pstrndup(r->pool, var, var_len), ap_pstrndup(r->pool, val, val_len)); RETURN_TRUE;}/* }}} *//* {{{ proto object apache_lookup_uri(string URI) Perform a partial request of the given URI to obtain information about it */PHP_FUNCTION(apache_lookup_uri){ pval **filename; request_rec *rr=NULL; if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(filename); if(!(rr = sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed '%s'", (*filename)->value.str.val); RETURN_FALSE; } object_init(return_value); add_property_long(return_value,"status", rr->status); if (rr->the_request) { add_property_string(return_value,"the_request", rr->the_request, 1); } if (rr->status_line) { add_property_string(return_value,"status_line", (char *)rr->status_line, 1); } if (rr->method) { add_property_string(return_value,"method", (char *)rr->method, 1); } if (rr->content_type) { add_property_string(return_value,"content_type", (char *)rr->content_type, 1); } if (rr->handler) { add_property_string(return_value,"handler", (char *)rr->handler, 1); } if (rr->uri) { add_property_string(return_value,"uri", rr->uri, 1); } if (rr->filename) { add_property_string(return_value,"filename", rr->filename, 1); } if (rr->path_info) { add_property_string(return_value,"path_info", rr->path_info, 1); } if (rr->args) { add_property_string(return_value,"args", rr->args, 1); } if (rr->boundary) { add_property_string(return_value,"boundary", rr->boundary, 1); } add_property_long(return_value,"no_cache", rr->no_cache); add_property_long(return_value,"no_local_copy", rr->no_local_copy); add_property_long(return_value,"allowed", rr->allowed); add_property_long(return_value,"sent_bodyct", rr->sent_bodyct); add_property_long(return_value,"bytes_sent", rr->bytes_sent); add_property_long(return_value,"byterange", rr->byterange); add_property_long(return_value,"clength", rr->clength);#if MODULE_MAGIC_NUMBER >= 19980324 if (rr->unparsed_uri) { add_property_string(return_value,"unparsed_uri", rr->unparsed_uri, 1); } if(rr->mtime) { add_property_long(return_value,"mtime", rr->mtime); }#endif if(rr->request_time) { add_property_long(return_value,"request_time", rr->request_time); } destroy_sub_req(rr);}/* }}} *//* {{{ proto string apache_get_version(void) Fetch Apache version */PHP_FUNCTION(apache_get_version){ char *apv = (char *) ap_get_server_version(); if (apv && *apv) { RETURN_STRING(apv, 1); } else { RETURN_FALSE; }}/* }}} */#if 0This function is most likely a bad idea. Just playing with it for now.PHP_FUNCTION(apache_exec_uri){ pval **filename; request_rec *rr=NULL; TSRMLS_FETCH(); if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(filename); if(!(rr = ap_sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed", (*filename)->value.str.val); RETURN_FALSE; } RETVAL_LONG(ap_run_sub_req(rr)); ap_destroy_sub_req(rr);}#endif/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -