wiki.techinc.nl/includes/WebResponse.php
Aaron Schulz c155fd4e4a Revert r43804 'This should probably be in Response, not Request, as we're setting data, not getting it. Nothing's using it yet (fairly new), so nothing to update.'
Session id is used by client request to specify its login data from cookie, so the session data, by extensions, is like a sort of request parameter. Also, WebResponse.php seems to be used for data actually sent to the client, like requested cookies.
2008-11-21 09:55:13 +00:00

60 lines
1.6 KiB
PHP

<?php
/**
* Allow programs to request this object from WebRequest::response()
* and handle all outputting (or lack of outputting) via it.
* @ingroup HTTP
*/
class WebResponse {
/**
* Output a HTTP header, wrapper for PHP's
* header()
* @param $string String: header to output
* @param $replace Bool: replace current similar header
*/
public function header($string, $replace=true) {
header($string,$replace);
}
/** Set the browser cookie
* @param $name String: name of cookie
* @param $value String: value to give cookie
* @param $expire Int: number of seconds til cookie expires
*/
public function setcookie( $name, $value, $expire = 0 ) {
global $wgCookiePath, $wgCookiePrefix, $wgCookieDomain;
global $wgCookieSecure,$wgCookieExpiration, $wgCookieHttpOnly;
if ( $expire == 0 ) {
$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 );
}
}
}