Viewing Paste 391

Formated Paste

  1. //bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )
  2. function set_cookie($name, $value = '', $expire = 0, $path = '', $domain = '', $secure = false, $httponly = false)
  3. {
  4. // This function is pointless if we have PHP >= 5.2.
  5. if (version_compare(PHP_VERSION, '5.2', '>='))
  6. return setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
  7.  
  8. // $httponly is the only reason I made this function. If it's not being used, use setcookie().
  9. if (!$httponly)
  10. return setcookie($name, $value, $expire, $path, $domain, $secure);
  11.  
  12. // Ugh, looks like we have to resort to using a manual process.
  13. header('Set-Cookie: '.rawurlencode($name).'='.rawurlencode($value)
  14. .(empty($domain) ? '' : '; Domain='.$domain)
  15. .(empty($expire) ? '' : '; Max-Age='.$expire)
  16. .(empty($path) ? '' : '; Path='.$path)
  17. .(!$secure ? '' : '; Secure')
  18. .(!$httponly ? '' : '; HttpOnly'), false);
  19. }
Name:
Email:
Code/text to paste:
  • Enable code highlighting
  • Code Language:
  • A duck, cat and a goose walk into a bar. How many animals walked into a bar?:
Highslide for Wordpress Plugin