#include "php_http_api.h"
#include "php_http_send_api.h"
#include "php_http_cache_api.h"
+#include "php_http_headers_api.h"
#include "php_http_request_method_api.h"
#ifdef HTTP_HAVE_CURL
# include "php_http_request_api.h"
REGISTER_INI_ENTRIES();
+ if (SUCCESS != http_headers_global_init()) {
+ return FAILURE;
+ }
if (SUCCESS != http_cache_global_init()) {
return FAILURE;
}
{
case 301: http_log(HTTP_G(log).redirect, "301-REDIRECT", header); break;
case 302: http_log(HTTP_G(log).redirect, "302-REDIRECT", header); break;
+ case 303: http_log(HTTP_G(log).redirect, "303-REDIRECT", header); break;
+ case 307: http_log(HTTP_G(log).redirect, "307-REDIRECT", header); break;
case 304: http_log(HTTP_G(log).cache, "304-CACHE", header); break;
case 405: http_log(HTTP_G(log).allowed_methods, "405-ALLOWED", header); break;
default: http_log(NULL, header, body); break;
}
/* }}} */
-/* {{{ proto void http_redirect([string url[, array params[, bool session,[ bool permanent]]]])
+/* {{{ proto void http_redirect([string url[, array params[, bool session[, int status]]]])
*
* Redirect to a given url.
* The supplied url will be expanded with http_absolute_uri(), the params array will
* be treated with http_build_query() and the session identification will be appended
* if session is true.
*
- * Depending on permanent the redirection will be issued with a permanent
- * ("301 Moved Permanently") or a temporary ("302 Found") redirection
- * status code.
+ * The HTTP response code will be set according to status.
+ * You can use one of the following constants for convenience:
+ * - HTTP_REDIRECT 302 Found
+ * - HTTP_REDIRECT_PERM 301 Moved Permanently
+ * - HTTP_REDIRECT_POST 303 See Other
+ * - HTTP_REDIRECT_TEMP 307 Temporary Redirect
+ *
+ * Please see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3
+ * for which redirect response code to use in which situation.
*
* To be RFC compliant, "Redirecting to <a>URI</a>." will be displayed,
- * if the client doesn't redirect immediatly.
+ * if the client doesn't redirect immediatly, and the request method was
+ * antoher than HEAD.
*/
PHP_FUNCTION(http_redirect)
{
int url_len;
size_t query_len = 0;
- zend_bool session = 0, permanent = 0, free_params = 0;
+ zend_bool session = 0, free_params = 0;
zval *params = NULL;
+ long status = 302;
char *query = NULL, *url = NULL, *URI, *LOC, *RED = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sa!/bb", &url, &url_len, ¶ms, &session, &permanent) != SUCCESS) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sa!/bl", &url, &url_len, ¶ms, &session, &status) != SUCCESS) {
RETURN_FALSE;
}
FREE_ZVAL(params);
}
- RETURN_SUCCESS(http_exit_ex(permanent ? 301 : 302, LOC, RED, 1));
+ RETURN_SUCCESS(http_exit_ex(status, LOC, RED, 1));
}
/* }}} */
# define HTTP_DBG_NEG 0
#endif
+/* {{{ STATUS http_headers_global_init() */
+STATUS _http_headers_global_init(INIT_FUNC_ARGS)
+{
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT", HTTP_REDIRECT);
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT_PERM", HTTP_REDIRECT_PERM);
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT_POST", HTTP_REDIRECT_POST);
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT_TEMP", HTTP_REDIRECT_TEMP);
+
+ return SUCCESS;
+}
+/* }}} */
+
/* {{{ static int http_sort_q(const void *, const void *) */
static int http_sort_q(const void *a, const void *b TSRMLS_DC)
{
DCL_STATIC_PROP(PROTECTED, double, throttleDelay, 0.0);
#ifndef WONKY
+ DCL_CONST(long, "REDIRECT", HTTP_REDIRECT);
+ DCL_CONST(long, "REDIRECT_PERM", HTTP_REDIRECT_PERM);
+ DCL_CONST(long, "REDIRECT_POST", HTTP_REDIRECT_POST);
+ DCL_CONST(long, "REDIRECT_TEMP", HTTP_REDIRECT_TEMP);
+
DCL_CONST(long, "ETAG_MD5", HTTP_ETAG_MD5);
DCL_CONST(long, "ETAG_SHA1", HTTP_ETAG_SHA1);
DCL_CONST(long, "ETAG_CRC32", HTTP_ETAG_CRC32);
#ifndef PHP_EXT_HTTP_H
#define PHP_EXT_HTTP_H
-#define HTTP_PEXT_VERSION "0.14.1"
+#define HTTP_PEXT_VERSION "0.14.2dev"
/* make compile on Win32 */
#ifdef HTTP_HAVE_CURL
#include "php_http_std_defs.h"
#include "php_http_info_api.h"
+#define HTTP_REDIRECT 302L
+#define HTTP_REDIRECT_PERM 301L
+#define HTTP_REDIRECT_POST 303L
+#define HTTP_REDIRECT_TEMP 307L
+
typedef enum {
RANGE_OK,
RANGE_NO,
RANGE_ERR
} http_range_status;
+#define http_headers_global_init() _http_headers_global_init(INIT_FUNC_ARGS_PASSTHRU)
+extern STATUS _http_headers_global_init(INIT_FUNC_ARGS);
+
#define http_parse_headers(h, a) _http_parse_headers_ex((h), Z_ARRVAL_P(a), 1, http_info_default_callback, NULL TSRMLS_CC)
#define http_parse_headers_ex(h, ht, p) _http_parse_headers_ex((h), (ht), (p), http_info_default_callback, NULL TSRMLS_CC)
#define http_parse_headers_cb(h, ht, p, f, d) _http_parse_headers_ex((h), (ht), (p), (f), (d) TSRMLS_CC)
<?php
include 'log.inc';
log_prepare(_REDIR_LOG);
-http_redirect('redirect', null, false, true);
+http_redirect('redirect', null, false, HTTP_REDIRECT_PERM);
?>
--EXPECTF--
Status: 301