cvs: pear /HTTP_Header Header.php
| From: | Wolfram Kriesing | Date: | Sun, 19 Jan 2003 20:05:27 +0000 |
| Subject: | cvs: pear /HTTP_Header Header.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-8420@lists.php.net to get a copy of this message | ||
cain Sun Jan 19 15:05:27 2003 EDT
Modified files:
/pear/HTTP_Header Header.php
Log:
- add redirect method
Index: pear/HTTP_Header/Header.php
diff -u pear/HTTP_Header/Header.php:1.2 pear/HTTP_Header/Header.php:1.3
--- pear/HTTP_Header/Header.php:1.2 Fri Jan 17 10:36:13 2003
+++ pear/HTTP_Header/Header.php Sun Jan 19 15:05:26 2003
@@ -15,14 +15,14 @@
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: Header.php,v 1.2 2003/01/17 15:36:13 cain Exp $
+// $Id: Header.php,v 1.3 2003/01/19 20:05:26 cain Exp $
require_once 'PEAR.php';
require_once 'HTTP.php';
-define( HTTP_HEADER_STATUS_304 , '304 Not modified' );
+define( 'HTTP_HEADER_STATUS_304' , '304 Not modified' );
@@ -133,6 +133,49 @@
print $dateTime->format(strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
*/
}
+
+ /**
+ * This function redirects the client. This is done by issuing
+ * a Location: header and exiting.
+ * Additionally to HTTP::redirect you can also add parameters to the url.
+ * If you dont need parameters to be added, simply use
+ * HTTP::redirect
+ * otherwise
+ * HTTP_Header::redirect
+ *
+ * @see HTTP::redirect()
+ * @author Wolfram Kriesing <wk@visionp.de>
+ * @param string $url URL where the redirect should go to
+ * @param mixed (1) true (default) - only the session-id will be added, this is very useful
+ * when using trans_sid<br>
+ * (2) false - no paras to add<br>
+ * (3) array - of parameter names, if the key is a string its assumed
+ * to be name=>value, otherwise the value is retreived using
+ * $GLOBALS['paraName']
+ */
+ function redirect($url,$param=true)
+ {
+ // true means add the session id only
+ if ($param === true) {
+ $param = array( session_name() => session_id() );
+ }
+ // add some other vars
+ if(is_array($param) && sizeof($param)) {
+ $paraString = array();
+ foreach ($param as $key=>$aParam) {
+ if (!is_string($key)) {
+ $paraString[] = urlencode($aParam).'='.urlencode(@$GLOBALS[$aParam]);
+ } else {
+ $paraString[] = urlencode($key).'='.urlencode($aParam);
+ }
+ }
+ $url .= '?'.implode('&',$paraString);
+ }
+
+ parent::redirect( $url );
+
+ }
+
}
?>