2006-08-12 23:03:53 +00:00
|
|
|
<?php
|
2007-04-21 12:42:27 +00:00
|
|
|
/**
|
|
|
|
|
* Allow programs to request this object from WebRequest::response()
|
|
|
|
|
* and handle all outputting (or lack of outputting) via it.
|
2008-09-03 17:30:20 +00:00
|
|
|
* @ingroup HTTP
|
2006-08-12 23:03:53 +00:00
|
|
|
*/
|
|
|
|
|
class WebResponse {
|
2007-04-21 12:42:27 +00:00
|
|
|
|
2008-08-24 03:06:03 +00:00
|
|
|
/**
|
|
|
|
|
* Output a HTTP header, wrapper for PHP's
|
|
|
|
|
* header()
|
|
|
|
|
* @param string $string Header to output
|
|
|
|
|
* @param bool $replace Replace current similar header
|
|
|
|
|
*/
|
|
|
|
|
public function header($string, $replace=true) {
|
2006-08-12 23:03:53 +00:00
|
|
|
header($string,$replace);
|
|
|
|
|
}
|
2007-04-21 12:42:27 +00:00
|
|
|
|
2008-08-24 03:06:03 +00:00
|
|
|
/** Set the browser cookie
|
|
|
|
|
* @param string $name Name of cookie
|
|
|
|
|
* @param string $value Value to give cookie
|
|
|
|
|
* @param int $expire Number of seconds til cookie expires
|
|
|
|
|
*/
|
|
|
|
|
public function setcookie( $name, $value, $expire = 0 ) {
|
2008-08-15 01:54:59 +00:00
|
|
|
global $wgCookiePath, $wgCookiePrefix, $wgCookieDomain;
|
|
|
|
|
global $wgCookieSecure,$wgCookieExpiration, $wgCookieHttpOnly;
|
2008-08-18 19:57:01 +00:00
|
|
|
if ( $expire == 0 ) {
|
2008-08-15 01:54:59 +00:00
|
|
|
$expire = time() + $wgCookieExpiration;
|
|
|
|
|
}
|
|
|
|
|
$httpOnlySafe = wfHttpOnlySafe();
|
|
|
|
|
wfDebugLog( 'cookie',
|
|
|
|
|
'setcookie: "' . implode( '", "',
|
|
|
|
|
array(
|
|
|
|
|
$wgCookiePrefix . $name,
|
|
|
|
|
$value,
|
|
|
|
|
$expire,
|
|
|
|
|
$wgCookiePath,
|
|
|
|
|
$wgCookieDomain,
|
|
|
|
|
$wgCookieSecure,
|
|
|
|
|
$httpOnlySafe && $wgCookieHttpOnly ) ) . '"' );
|
|
|
|
|
if( $httpOnlySafe && isset( $wgCookieHttpOnly ) ) {
|
|
|
|
|
setcookie( $wgCookiePrefix . $name,
|
|
|
|
|
$value,
|
|
|
|
|
$expire,
|
|
|
|
|
$wgCookiePath,
|
|
|
|
|
$wgCookieDomain,
|
|
|
|
|
$wgCookieSecure,
|
|
|
|
|
$wgCookieHttpOnly );
|
|
|
|
|
} else {
|
|
|
|
|
// setcookie() fails on PHP 5.1 if you give it future-compat paramters.
|
|
|
|
|
// stab stab!
|
|
|
|
|
setcookie( $wgCookiePrefix . $name,
|
|
|
|
|
$value,
|
|
|
|
|
$expire,
|
|
|
|
|
$wgCookiePath,
|
|
|
|
|
$wgCookieDomain,
|
|
|
|
|
$wgCookieSecure );
|
|
|
|
|
}
|
2006-08-12 23:03:53 +00:00
|
|
|
}
|
|
|
|
|
}
|