2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
19 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
28 #include "ext/standard/info.h"
29 #include "ext/session/php_session.h"
30 #include "ext/standard/php_string.h"
31 #include "ext/standard/php_smart_str.h"
36 #include "php_http_api.h"
37 #include "php_http_curl_api.h"
39 ZEND_DECLARE_MODULE_GLOBALS(http
)
41 /* {{{ proto string http_date([int timestamp])
43 * This function returns a valid HTTP date regarding RFC 822/1123
44 * looking like: "Wed, 22 Dec 2004 11:34:47 GMT"
47 PHP_FUNCTION(http_date
)
51 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &t
) != SUCCESS
) {
56 t
= (long) time(NULL
);
59 RETURN_STRING(http_date(t
), 0);
63 /* {{{ proto string http_absolute_uri(string url[, string proto])
65 * This function returns an absolute URI constructed from url.
66 * If the url is already abolute but a different proto was supplied,
67 * only the proto part of the URI will be updated. If url has no
68 * path specified, the path of the current REQUEST_URI will be taken.
69 * The host will be taken either from the Host HTTP header of the client
70 * the SERVER_NAME or just localhost if prior are not available.
74 * url = "page.php" => http://www.example.com/current/path/page.php
75 * url = "/page.php" => http://www.example.com/page.php
76 * url = "/page.php", proto = "https" => https://www.example.com/page.php
80 PHP_FUNCTION(http_absolute_uri
)
82 char *url
= NULL
, *proto
= NULL
;
83 int url_len
= 0, proto_len
= 0;
85 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|s", &url
, &url_len
, &proto
, &proto_len
) != SUCCESS
) {
89 RETURN_STRING(http_absolute_uri(url
, proto
), 0);
93 /* {{{ proto string http_negotiate_language(array supported[, string default = 'en-US'])
95 * This function negotiates the clients preferred language based on its
96 * Accept-Language HTTP header. It returns the negotiated language or
97 * the default language if none match.
99 * The qualifier is recognized and languages without qualifier are rated highest.
101 * The supported parameter is expected to be an array having
102 * the supported languages as array values.
116 * include './langs/'. http_negotiate_language($langs) .'.php';
121 PHP_FUNCTION(http_negotiate_language
)
127 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a|s", &supported
, &def
, &def_len
) != SUCCESS
) {
135 RETURN_STRING(http_negotiate_language(supported
, def
), 0);
139 /* {{{ proto string http_negotiate_charset(array supported[, string default = 'iso-8859-1'])
141 * This function negotiates the clients preferred charset based on its
142 * Accept-Charset HTTP header. It returns the negotiated charset or
143 * the default charset if none match.
145 * The qualifier is recognized and charset without qualifier are rated highest.
147 * The supported parameter is expected to be an array having
148 * the supported charsets as array values.
154 * 'iso-8859-1', // default
159 * $pref = http_negotiate_charset($charsets);
160 * if (!strcmp($pref, 'iso-8859-1')) {
161 * iconv_set_encoding('internal_encoding', 'iso-8859-1');
162 * iconv_set_encoding('output_encoding', $pref);
163 * ob_start('ob_iconv_handler');
168 PHP_FUNCTION(http_negotiate_charset
)
174 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a|s", &supported
, &def
, &def_len
) != SUCCESS
) {
182 RETURN_STRING(http_negotiate_charset(supported
, def
), 0);
186 /* {{{ proto bool http_send_status(int status)
188 * Send HTTP status code.
191 PHP_FUNCTION(http_send_status
)
195 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &status
) != SUCCESS
) {
198 if (status
< 100 || status
> 510) {
199 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Invalid HTTP status code (100-510): %d", status
);
203 RETURN_SUCCESS(http_send_status(status
));
207 /* {{{ proto bool http_send_last_modified([int timestamp])
209 * This converts the given timestamp to a valid HTTP date and
210 * sends it as "Last-Modified" HTTP header. If timestamp is
211 * omitted, current time is sent.
214 PHP_FUNCTION(http_send_last_modified
)
218 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &t
) != SUCCESS
) {
223 t
= (long) time(NULL
);
226 RETURN_SUCCESS(http_send_last_modified(t
));
230 /* {{{ proto bool http_send_content_type([string content_type = 'application/x-octetstream'])
232 * Sets the content type.
235 PHP_FUNCTION(http_send_content_type
)
240 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &ct
, &ct_len
) != SUCCESS
) {
245 RETURN_SUCCESS(http_send_content_type("application/x-octetstream", sizeof("application/x-octetstream") - 1));
247 RETURN_SUCCESS(http_send_content_type(ct
, ct_len
));
251 /* {{{ proto bool http_send_content_disposition(string filename[, bool inline = false])
253 * Set the Content Disposition. The Content-Disposition header is very useful
254 * if the data actually sent came from a file or something similar, that should
255 * be "saved" by the client/user (i.e. by browsers "Save as..." popup window).
258 PHP_FUNCTION(http_send_content_disposition
)
262 zend_bool send_inline
= 0;
264 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|b", &filename
, &f_len
, &send_inline
) != SUCCESS
) {
267 RETURN_SUCCESS(http_send_content_disposition(filename
, f_len
, send_inline
));
271 /* {{{ proto bool http_match_modified([int timestamp])
273 * Matches the given timestamp against the clients "If-Modified-Since" resp.
274 * "If-Unmodified-Since" HTTP headers.
277 PHP_FUNCTION(http_match_modified
)
281 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &t
) != SUCCESS
) {
285 // current time if not supplied (senseless though)
287 t
= (long) time(NULL
);
290 RETURN_BOOL(http_modified_match("HTTP_IF_MODIFIED_SINCE", t
) || http_modified_match("HTTP_IF_UNMODIFIED_SINCE", t
));
294 /* {{{ proto bool http_match_etag(string etag)
296 * This matches the given ETag against the clients
297 * "If-Match" resp. "If-None-Match" HTTP headers.
300 PHP_FUNCTION(http_match_etag
)
305 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &etag
, &etag_len
) != SUCCESS
) {
309 RETURN_BOOL(http_etag_match("HTTP_IF_NONE_MATCH", etag
) || http_etag_match("HTTP_IF_MATCH", etag
));
313 /* {{{ proto bool http_cache_last_modified([int timestamp_or_expires]])
315 * If timestamp_or_exires is greater than 0, it is handled as timestamp
316 * and will be sent as date of last modification. If it is 0 or omitted,
317 * the current time will be sent as Last-Modified date. If it's negative,
318 * it is handled as expiration time in seconds, which means that if the
319 * requested last modification date is not between the calculated timespan,
320 * the Last-Modified header is updated and the actual body will be sent.
323 PHP_FUNCTION(http_cache_last_modified
)
325 long last_modified
= 0, send_modified
= 0, t
;
328 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &last_modified
) != SUCCESS
) {
332 t
= (long) time(NULL
);
335 if (!last_modified
) {
336 /* does the client have? (att: caching "forever") */
337 if (zlm
= http_get_server_var("HTTP_IF_MODIFIED_SINCE")) {
338 last_modified
= send_modified
= http_parse_date(Z_STRVAL_P(zlm
));
339 /* send current time */
343 /* negative value is supposed to be expiration time */
344 } else if (last_modified
< 0) {
347 /* send supplied time explicitly */
349 send_modified
= last_modified
;
352 RETURN_SUCCESS(http_cache_last_modified(last_modified
, send_modified
, HTTP_DEFAULT_CACHECONTROL
, sizeof(HTTP_DEFAULT_CACHECONTROL
) - 1));
356 /* {{{ proto bool http_cache_etag([string etag])
358 * This function attempts to cache the HTTP body based on an ETag,
359 * either supplied or generated through calculation of the MD5
360 * checksum of the output (uses output buffering).
362 * If clients "If-None-Match" header matches the supplied/calculated
363 * ETag, the body is considered cached on the clients side and
364 * a "304 Not Modified" status code is issued.
367 PHP_FUNCTION(http_cache_etag
)
372 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &etag
, &etag_len
) != SUCCESS
) {
376 RETURN_SUCCESS(http_cache_etag(etag
, etag_len
, HTTP_DEFAULT_CACHECONTROL
, sizeof(HTTP_DEFAULT_CACHECONTROL
) - 1));
380 /* {{{ proto string ob_httpetaghandler(string data, int mode)
382 * For use with ob_start().
383 * Note that this has to be started as first output buffer.
384 * WARNING: Don't use with http_send_*().
386 PHP_FUNCTION(ob_httpetaghandler
)
392 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "sl", &data
, &data_len
, &mode
)) {
396 if (mode
& PHP_OUTPUT_HANDLER_START
) {
397 if (HTTP_G(etag_started
)) {
398 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "ob_httpetaghandler can only be used once");
399 RETURN_STRINGL(data
, data_len
, 1);
401 http_send_header("Cache-Control: " HTTP_DEFAULT_CACHECONTROL
);
402 HTTP_G(etag_started
) = 1;
405 if (OG(ob_nesting_level
) > 1) {
406 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "ob_httpetaghandler must be started prior to other output buffers");
407 RETURN_STRINGL(data
, data_len
, 1);
410 Z_TYPE_P(return_value
) = IS_STRING
;
411 http_ob_etaghandler(data
, data_len
, &Z_STRVAL_P(return_value
), &Z_STRLEN_P(return_value
), mode
);
415 /* {{{ proto void http_redirect([string url[, array params[, bool session,[ bool permanent]]]])
417 * Redirect to a given url.
418 * The supplied url will be expanded with http_absolute_uri(), the params array will
419 * be treated with http_build_query() and the session identification will be appended
420 * if session is true.
422 * Depending on permanent the redirection will be issued with a permanent
423 * ("301 Moved Permanently") or a temporary ("302 Found") redirection
426 * To be RFC compliant, "Redirecting to <a>URI</a>." will be displayed,
427 * if the client doesn't redirect immediatly.
429 PHP_FUNCTION(http_redirect
)
432 zend_bool session
= 0, permanent
= 0;
434 smart_str qstr
= {0};
435 char *url
, *URI
, LOC
[HTTP_URI_MAXLEN
+ 9], RED
[HTTP_URI_MAXLEN
* 2 + 34];
437 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|sa!/bb", &url
, &url_len
, ¶ms
, &session
, &permanent
) != SUCCESS
) {
441 /* append session info */
442 if (session
&& (PS(session_status
) == php_session_active
)) {
444 MAKE_STD_ZVAL(params
);
447 if (add_assoc_string(params
, PS(session_name
), PS(id
), 1) != SUCCESS
) {
448 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not append session information");
452 /* treat params array with http_build_query() */
454 if (php_url_encode_hash_ex(Z_ARRVAL_P(params
), &qstr
, NULL
,0,NULL
,0,NULL
,0,NULL TSRMLS_CC
) != SUCCESS
) {
458 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not encode query parameters");
464 URI
= http_absolute_uri(url
, NULL
);
466 snprintf(LOC
, HTTP_URI_MAXLEN
+ strlen("Location: "), "Location: %s?%s", URI
, qstr
.c
);
467 sprintf(RED
, "Redirecting to <a href=\"%s?%s\">%s?%s</a>.\n", URI
, qstr
.c
, URI
, qstr
.c
);
470 snprintf(LOC
, HTTP_URI_MAXLEN
+ strlen("Location: "), "Location: %s", URI
);
471 sprintf(RED
, "Redirecting to <a href=\"%s\">%s</a>.\n", URI
, URI
);
475 if ((SUCCESS
== http_send_header(LOC
)) && (SUCCESS
== http_send_status((permanent
? 301 : 302)))) {
476 php_body_write(RED
, strlen(RED
) TSRMLS_CC
);
483 /* {{{ proto bool http_send_data(string data)
485 * Sends raw data with support for (multiple) range requests.
488 PHP_FUNCTION(http_send_data
)
492 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &zdata
) != SUCCESS
) {
496 convert_to_string_ex(&zdata
);
497 http_send_header("Accept-Ranges: bytes");
498 RETURN_SUCCESS(http_send_data(zdata
));
502 /* {{{ proto bool http_send_file(string file)
504 * Sends a file with support for (multiple) range requests.
507 PHP_FUNCTION(http_send_file
)
511 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &zfile
) != SUCCESS
) {
515 convert_to_string_ex(&zfile
);
516 http_send_header("Accept-Ranges: bytes");
517 RETURN_SUCCESS(http_send_file(zfile
));
521 /* {{{ proto bool http_send_stream(resource stream)
523 * Sends an already opened stream with support for (multiple) range requests.
526 PHP_FUNCTION(http_send_stream
)
531 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "r", &zstream
) != SUCCESS
) {
535 php_stream_from_zval(file
, &zstream
);
536 http_send_header("Accept-Ranges: bytes");
537 RETURN_SUCCESS(http_send_stream(file
));
541 /* {{{ proto string http_chunked_decode(string encoded)
543 * This function decodes a string that was HTTP-chunked encoded.
544 * Returns false on failure.
546 PHP_FUNCTION(http_chunked_decode
)
548 char *encoded
= NULL
, *decoded
= NULL
;
549 int encoded_len
= 0, decoded_len
= 0;
551 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &encoded
, &encoded_len
) != SUCCESS
) {
555 if (SUCCESS
== http_chunked_decode(encoded
, encoded_len
, &decoded
, &decoded_len
)) {
556 RETURN_STRINGL(decoded
, decoded_len
, 0);
563 /* {{{ proto array http_split_response(string http_response)
565 * This function splits an HTTP response into an array with headers and the
566 * content body. The returned array may look simliar to the following example:
572 * 'Status' => '200 Ok',
573 * 'Content-Type' => 'text/plain',
574 * 'Content-Language' => 'en-US'
576 * 1 => "Hello World!"
581 PHP_FUNCTION(http_split_response
)
583 zval
*zresponse
, *zbody
, *zheaders
;
585 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &zresponse
) != SUCCESS
) {
589 convert_to_string_ex(&zresponse
);
591 MAKE_STD_ZVAL(zbody
);
592 MAKE_STD_ZVAL(zheaders
);
593 array_init(zheaders
);
595 if (SUCCESS
!= http_split_response(zresponse
, zheaders
, zbody
)) {
596 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not parse HTTP response");
600 array_init(return_value
);
601 add_index_zval(return_value
, 0, zheaders
);
602 add_index_zval(return_value
, 1, zbody
);
606 /* {{{ proto array http_parse_headers(string header)
609 PHP_FUNCTION(http_parse_headers
)
614 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &header
, &header_len
)) {
618 array_init(return_value
);
620 if (rnrn
= strstr(header
, HTTP_CRLF HTTP_CRLF
)) {
621 header_len
= rnrn
- header
+ 2;
623 if (SUCCESS
!= http_parse_headers(header
, header_len
, return_value
)) {
624 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not parse HTTP header");
625 zval_dtor(return_value
);
631 /* {{{ proto array http_get_request_headers(void)
634 PHP_FUNCTION(http_get_request_headers
)
636 if (ZEND_NUM_ARGS()) {
640 array_init(return_value
);
641 http_get_request_headers(return_value
);
646 #ifdef HTTP_HAVE_CURL
648 /* {{{ proto string http_get(string url[, array options[, array &info]])
650 * Performs an HTTP GET request on the supplied url.
652 * The second parameter is expected to be an associative
653 * array where the following keys will be recognized:
655 * - redirect: int, whether and how many redirects to follow
656 * - unrestrictedauth: bool, whether to continue sending credentials on
657 * redirects to a different host
658 * - proxyhost: string, proxy host in "host[:port]" format
659 * - proxyport: int, use another proxy port as specified in proxyhost
660 * - proxyauth: string, proxy credentials in "user:pass" format
661 * - proxyauthtype: int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM
662 * - httpauth: string, http credentials in "user:pass" format
663 * - httpauthtype: int, HTTP_AUTH_BASIC, DIGEST and/or NTLM
664 * - compress: bool, whether to allow gzip/deflate content encoding
666 * - port: int, use another port as specified in the url
667 * - referer: string, the referer to sends
668 * - useragent: string, the user agent to send
669 * (defaults to PECL::HTTP/version (PHP/version)))
670 * - headers: array, list of custom headers as associative array
671 * like array("header" => "value")
672 * - cookies: array, list of cookies as associative array
673 * like array("cookie" => "value")
674 * - cookiestore: string, path to a file where cookies are/will be stored
677 * The optional third parameter will be filled with some additional information
678 * in form af an associative array, if supplied, like the following example:
682 * 'effective_url' => 'http://localhost',
683 * 'response_code' => 403,
684 * 'total_time' => 0.017,
685 * 'namelookup_time' => 0.013,
686 * 'connect_time' => 0.014,
687 * 'pretransfer_time' => 0.014,
688 * 'size_upload' => 0,
689 * 'size_download' => 202,
690 * 'speed_download' => 11882,
691 * 'speed_upload' => 0,
692 * 'header_size' => 145,
693 * 'request_size' => 62,
694 * 'ssl_verifyresult' => 0,
696 * 'content_length_download' => 202,
697 * 'content_length_upload' => 0,
698 * 'starttransfer_time' => 0.017,
699 * 'content_type' => 'text/html; charset=iso-8859-1',
700 * 'redirect_time' => 0,
701 * 'redirect_count' => 0,
703 * 'http_connectcode' => 0,
704 * 'httpauth_avail' => 0,
705 * 'proxyauth_avail' => 0,
710 PHP_FUNCTION(http_get
)
712 char *URL
, *data
= NULL
;
715 zval
*options
= NULL
, *info
= NULL
;
717 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|a/!z", &URL
, &URL_len
, &options
, &info
) != SUCCESS
) {
726 if (SUCCESS
== http_get(URL
, HASH_ORNULL(options
), HASH_ORNULL(info
), &data
, &data_len
)) {
727 RETURN_STRINGL(data
, data_len
, 0);
734 /* {{{ proto string http_head(string url[, array options[, array &info]])
736 * Performs an HTTP HEAD request on the suppied url.
737 * Returns the HTTP response as string.
738 * See http_get() for a full list of available options.
740 PHP_FUNCTION(http_head
)
742 char *URL
, *data
= NULL
;
745 zval
*options
= NULL
, *info
= NULL
;
747 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|a/!z", &URL
, &URL_len
, &options
, &info
) != SUCCESS
) {
756 if (SUCCESS
== http_head(URL
, HASH_ORNULL(options
), HASH_ORNULL(info
), &data
, &data_len
)) {
757 RETURN_STRINGL(data
, data_len
, 0);
764 /* {{{ proto string http_post_data(string url, string data[, array options[, &info]])
766 * Performs an HTTP POST request, posting data.
767 * Returns the HTTP response as string.
768 * See http_get() for a full list of available options.
770 PHP_FUNCTION(http_post_data
)
772 char *URL
, *postdata
, *data
= NULL
;
774 int postdata_len
, URL_len
;
775 zval
*options
= NULL
, *info
= NULL
;
777 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ss|a/!z", &URL
, &URL_len
, &postdata
, &postdata_len
, &options
, &info
) != SUCCESS
) {
786 if (SUCCESS
== http_post_data(URL
, postdata
, (size_t) postdata_len
, HASH_ORNULL(options
), HASH_ORNULL(info
), &data
, &data_len
)) {
787 RETURN_STRINGL(data
, data_len
, 0);
794 /* {{{ proto string http_post_array(string url, array data[, array options[, array &info]])
796 * Performs an HTTP POST request, posting www-form-urlencoded array data.
797 * Returns the HTTP response as string.
798 * See http_get() for a full list of available options.
800 PHP_FUNCTION(http_post_array
)
802 char *URL
, *data
= NULL
;
805 zval
*options
= NULL
, *info
= NULL
, *postdata
;
807 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "sa|a/!z", &URL
, &URL_len
, &postdata
, &options
, &info
) != SUCCESS
) {
816 if (SUCCESS
== http_post_array(URL
, Z_ARRVAL_P(postdata
), HASH_ORNULL(options
), HASH_ORNULL(info
), &data
, &data_len
)) {
817 RETURN_STRINGL(data
, data_len
, 0);
828 /* {{{ proto bool http_auth_basic(string user, string pass[, string realm = "Restricted"])
833 * if (!http_auth_basic('mike', 's3c|r3t')) {
834 * die('<h1>Authorization failed!</h1>');
839 PHP_FUNCTION(http_auth_basic
)
841 char *realm
= NULL
, *user
, *pass
, *suser
, *spass
;
842 int r_len
, u_len
, p_len
;
844 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ss|s", &user
, &u_len
, &pass
, &p_len
, &realm
, &r_len
) != SUCCESS
) {
849 realm
= "Restricted";
852 if (SUCCESS
!= http_auth_credentials(&suser
, &spass
)) {
853 http_auth_header("Basic", realm
);
857 if (strcasecmp(suser
, user
)) {
858 http_auth_header("Basic", realm
);
862 if (strcmp(spass
, pass
)) {
863 http_auth_header("Basic", realm
);
871 /* {{{ proto bool http_auth_basic_cb(mixed callback[, string realm = "Restricted"])
876 * function auth_cb($user, $pass)
879 * $query = 'SELECT pass FROM users WHERE user='. $db->quoteSmart($user);
880 * if (strlen($realpass = $db->getOne($query)) {
881 * return $pass === $realpass;
886 * if (!http_auth_basic_cb('auth_cb')) {
887 * die('<h1>Authorization failed</h1>');
892 PHP_FUNCTION(http_auth_basic_cb
)
895 char *realm
= NULL
, *user
, *pass
;
898 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z|s", &cb
, &realm
, &r_len
) != SUCCESS
) {
903 realm
= "Restricted";
906 if (SUCCESS
!= http_auth_credentials(&user
, &pass
)) {
907 http_auth_header("Basic", realm
);
911 zval
*zparams
[2] = {NULL
, NULL
}, retval
;
914 MAKE_STD_ZVAL(zparams
[0]);
915 MAKE_STD_ZVAL(zparams
[1]);
916 ZVAL_STRING(zparams
[0], user
, 0);
917 ZVAL_STRING(zparams
[1], pass
, 0);
919 if (SUCCESS
== call_user_function(EG(function_table
), NULL
, cb
,
920 &retval
, 2, zparams TSRMLS_CC
)) {
921 result
= Z_LVAL(retval
);
930 http_auth_header("Basic", realm
);
944 * vim600: noet sw=4 ts=4 fdm=marker
945 * vim<600: noet sw=4 ts=4