[an error occurred while processing the directive]
- http_cache_etag
- http_cache_last_modified
- http_chunked_decode
- http_deflate
- http_inflate
- 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
- http_negotiate_charset
- http_negotiate_content_type
- http_negotiate_language
- ob_deflatehandler
- ob_etaghandler
- ob_inflatehandler
- http_parse_cookie
- http_parse_headers
- http_parse_message
- http_parse_params
- http_persistent_handles_clean
- http_persistent_handles_count
- http_persistent_handles_ident
- 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
- 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
- http_build_str
- http_build_url
Коментарии
alternative:
<?php
function cookie_parse( $header ) {
$cookies = array();
foreach( $header as $line ) {
if( preg_match( '/^Set-Cookie: /i', $line ) ) {
$line = preg_replace( '/^Set-Cookie: /i', '', trim( $line ) );
$csplit = explode( ';', $line );
$cdata = array();
foreach( $csplit as $data ) {
$cinfo = explode( '=', $data );
$cinfo[0] = trim( $cinfo[0] );
if( $cinfo[0] == 'expires' ) $cinfo[1] = strtotime( $cinfo[1] );
if( $cinfo[0] == 'secure' ) $cinfo[1] = "true";
if( in_array( $cinfo[0], array( 'domain', 'expires', 'path', 'secure', 'comment' ) ) ) {
$cdata[trim( $cinfo[0] )] = $cinfo[1];
}
else {
$cdata['value']['key'] = $cinfo[0];
$cdata['value']['value'] = $cinfo[1];
}
}
$cookies[] = $cdata;
}
}
return $cookies;
}
function cookie_build( $data ) {
if( is_array( $data ) ) {
$cookie = '';
foreach( $data as $d ) {
$cookie[] = $d['value']['key'].'='.$d['value']['value'];
}
if( count( $cookie ) > 0 ) {
return trim( implode( '; ', $cookie ) );
}
}
return false;
}
?>
(http://www.seo-blackhat.com/article/the-cookie-backer-php.html)
Here's a good way to get cookies from a page and then resubimit the data to that page (or acess any other page using the cookies gotten).
<?php
//SOME DATA TO POST
$postData = array
(
'user' => $login,
'pass' => $pass
);
//FIRST POST
$post1 = http_post_fields('http://example.com', $postData);
//GET THE COOKIES STORED TO THE ARRAY $cookie
preg_match('/Set-Cookie: (.*)\b/', $post1, $cookie);
$cookie = (array) http_parse_cookie($cookie[1]);
$cookie = array( 'cookies' => $cookie["cookies"]);
//POST DATA NOW WITH THE COOKIE
$post2 = http_post_fields('http://example.com', $postData, array(), $cookie);
?>
I don't think you can split the cookie-line on ";", since the semicolon is allowed withing double-quotes, eg.:
Set-Cookie: COOKIE1="a;b;c"; path=/xyz; Max-Age=100
For ghpille at hotmail dot:
Actually, RFC 6265 describes, in section 4.1.1., that quoted or not, the value of a cookie can be specified using "US-ASCII characters excluding CTLs, whitespace DQUOTE, comma, semicolon, and backslash". Therefore, your example is an invalid cookie, according to this document, which replaces RFC 2965, and the value of a "Set-Cookie" header field can be parsed using a simple explode(';', $cookie_field_value) call.