WebResponse.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Allow programs to request this object from WebRequest::response()
  4. * and handle all outputting (or lack of outputting) via it.
  5. * @ingroup HTTP
  6. */
  7. class WebResponse {
  8. /**
  9. * Output a HTTP header, wrapper for PHP's
  10. * header()
  11. * @param $string String: header to output
  12. * @param $replace Bool: replace current similar header
  13. */
  14. public function header($string, $replace=true) {
  15. header($string,$replace);
  16. }
  17. /** Set the browser cookie
  18. * @param $name String: name of cookie
  19. * @param $value String: value to give cookie
  20. * @param $expire Int: number of seconds til cookie expires
  21. */
  22. public function setcookie( $name, $value, $expire = 0 ) {
  23. global $wgCookiePath, $wgCookiePrefix, $wgCookieDomain;
  24. global $wgCookieSecure,$wgCookieExpiration, $wgCookieHttpOnly;
  25. if ( $expire == 0 ) {
  26. $expire = time() + $wgCookieExpiration;
  27. }
  28. $httpOnlySafe = wfHttpOnlySafe();
  29. wfDebugLog( 'cookie',
  30. 'setcookie: "' . implode( '", "',
  31. array(
  32. $wgCookiePrefix . $name,
  33. $value,
  34. $expire,
  35. $wgCookiePath,
  36. $wgCookieDomain,
  37. $wgCookieSecure,
  38. $httpOnlySafe && $wgCookieHttpOnly ) ) . '"' );
  39. if( $httpOnlySafe && isset( $wgCookieHttpOnly ) ) {
  40. setcookie( $wgCookiePrefix . $name,
  41. $value,
  42. $expire,
  43. $wgCookiePath,
  44. $wgCookieDomain,
  45. $wgCookieSecure,
  46. $wgCookieHttpOnly );
  47. } else {
  48. // setcookie() fails on PHP 5.1 if you give it future-compat paramters.
  49. // stab stab!
  50. setcookie( $wgCookiePrefix . $name,
  51. $value,
  52. $expire,
  53. $wgCookiePath,
  54. $wgCookieDomain,
  55. $wgCookieSecure );
  56. }
  57. }
  58. }