文字

HTTP 函数

Built-in HTTP related functions previously listed on this page can be found in the networking category.

The following functions do not need the HTTP module to be present: header() , headers_list() , headers_sent() , setcookie() setrawcookie() .

Function groups

Caching

  • http_cache_etag()
  • http_cache_last_modified()

Encodings

  • http_chunked_decode()
  • http_deflate()
  • http_inflate()

Miscellaneous

  • http_build_cookie()
  • http_date()
  • http_get_request_body_stream()
  • http_get_request_body()
  • http_get_request_headers()
  • http_match_etag()
  • http_match_modified()
  • http_match_request_header()
  • http_support()

Negotiation

  • http_negotiate_charset()
  • http_negotiate_content_type()
  • http_negotiate_language()

Outputhandlers

  • ob_deflatehandler()
  • ob_etaghandler()
  • ob_inflatehandler()

Parsers

  • http_parse_cookie()
  • http_parse_headers()
  • http_parse_message()
  • http_parse_params()

Requests

  • http_get()
  • http_head()
  • http_post_data()
  • http_post_fields()
  • http_put_data()
  • http_put_file()
  • http_put_stream()
  • http_request_body_encode()
  • http_request_method_exists()
  • http_request_method_name()
  • http_request_method_register()
  • http_request_method_unregister()
  • http_request()

Responses

  • http_redirect()
  • http_send_content_disposition()
  • http_send_content_type()
  • http_send_data()
  • http_send_file()
  • http_send_last_modified()
  • http_send_status()
  • http_send_stream()
  • http_throttle()

URLs

  • http_build_str()
  • http_build_url()

Persistent Handles

  • http_persistent_handles_count()
  • http_persistent_handles_ident()
  • http_persistent_handles_clean()

Table of Contents

  • http_cache_etag — Caching by ETag
  • http_cache_last_modified — Caching by last modification
  • http_chunked_decode — Decode chunked-encoded data
  • http_deflate — Deflate data
  • http_inflate — Inflate data
  • http_build_cookie — Build cookie string
  • http_date — Compose HTTP RFC compliant date
  • http_get_request_body_stream — Get request body as stream
  • http_get_request_body — Get request body as string
  • http_get_request_headers — Get request headers as array
  • http_match_etag — Match ETag
  • http_match_modified — Match last modification
  • http_match_request_header — Match any header
  • http_support — Check built-in HTTP support
  • http_negotiate_charset — Negotiate client's preferred character set
  • http_negotiate_content_type — Negotiate client's preferred content type
  • http_negotiate_language — Negotiate client's preferred language
  • ob_deflatehandler — Deflate output handler
  • ob_etaghandler — ETag output handler
  • ob_inflatehandler — Inflate output handler
  • http_parse_cookie — Parse HTTP cookie
  • http_parse_headers — Parse HTTP headers
  • http_parse_message — Parse HTTP messages
  • http_parse_params — Parse parameter list
  • http_persistent_handles_clean — Clean up persistent handles
  • http_persistent_handles_count — Stat persistent handles
  • http_persistent_handles_ident — Get/set ident of persistent handles
  • http_get — Perform GET request
  • http_head — Perform HEAD request
  • http_post_data — Perform POST request with pre-encoded data
  • http_post_fields — Perform POST request with data to be encoded
  • http_put_data — Perform PUT request with data
  • http_put_file — Perform PUT request with file
  • http_put_stream — Perform PUT request with stream
  • http_request_body_encode — Encode request body
  • http_request_method_exists — Check whether request method exists
  • http_request_method_name — Get request method name
  • http_request_method_register — Register request method
  • http_request_method_unregister — Unregister request method
  • http_request — Perform custom request
  • http_redirect — Issue HTTP redirect
  • http_send_content_disposition — Send Content-Disposition
  • http_send_content_type — Send Content-Type
  • http_send_data — Send arbitrary data
  • http_send_file — Send file
  • http_send_last_modified — Send Last-Modified
  • http_send_status — Send HTTP response status
  • http_send_stream — Send stream
  • http_throttle — HTTP throttling
  • http_build_str — 产生一个查询字符串
  • http_build_url — 产生一个 URL

用户评论:

[#1] henke dot andersson at comhem dot se [2006-01-14 13:01:27]

If you want to make outgoing http connections with php, concider the curl extension.

[#2] woei at xs4all dot nl [2005-11-30 07:57:03]

Actually, if you want to redirect a user why let HTML or JavaScript do it? Simply do this:

header("Location: http://www.example.com/");

[#3] WeeJames [2004-07-07 11:39:11]

Regarding what the guy before said.  We've experienced problems where certain firewalls have encrypted the HTTP_REFERER meaning that it doesnt always contain the place you've come from.

Better to track where the user has come from either in a form post or in the url.

[#4] [2004-04-27 19:05:38]

in reference to toashwinisidhu's and breaker's note, a more effective way would be to use meta-tag redirect, for example.

<?php
$url 
"http://somesite.com/index.php"// target of the redirect
$delay "3"// 3 second delay

echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';

?>


The meta goes in the head of the HTML.
This method does not require javascript and is supported by most browsers and is rarely, if ever, filterd out.

[#5] toashwinisidhu at yahoo dot com [2004-04-21 03:55:41]

The method given below may not sometimes work.
The following method has always worked with me:
just put the following 3 lines in your PHP code

?>
<body onload=setTimeout("location.href='$url'",$sec)>
<?PHP
-------?>


$sec is the time in second after which the browser would automatically go to the url. Set it to 0 if you do not want to give any time.
You can use this function on the events of various html/form objects (eg.-onclick for button).eg.
<input type=button value="Go to Php.net" onclick=setTimeout("location.href='php.net'",0)>
Use this to one step back
<input type="button" value="Back" onclick=history.go(-1)>

[#6] jeffp-php at outofservice dot com [2001-01-04 20:37:57]

$HTTP_RAW_POST_DATA --

You'll usually access variables from forms sent via POST method by just accessing the associated PHP global variable.

However, if your POST data is not URI encoded (i.e., custom application that's not form-based) PHP won't parse the data into nice variables for you.  You will need to use $HTTP_RAW_POST_DATA to access the raw data directly. (This should return a copy of the data given to the PHP process on STDIN; note that you wan't be able to open STDIN and read it yourself because PHP already did so itself.)

上一篇: 下一篇: