26 lines
712 B
PHP
26 lines
712 B
PHP
|
<?php
|
||
|
namespace Misuzu\Auth;
|
||
|
|
||
|
// is this the right way to do this?
|
||
|
|
||
|
final class AuthTokenCookie {
|
||
|
public static function domain(): string {
|
||
|
$url = parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST);
|
||
|
if(empty($url))
|
||
|
$url = $_SERVER['HTTP_HOST'];
|
||
|
|
||
|
if(!filter_var($url, FILTER_VALIDATE_IP))
|
||
|
$url = '.' . $url;
|
||
|
|
||
|
return $url;
|
||
|
}
|
||
|
|
||
|
public static function apply(string $packed): void {
|
||
|
setcookie('msz_auth', $packed, strtotime('+3 months'), '/', self::domain(), !empty($_SERVER['HTTPS']), true);
|
||
|
}
|
||
|
|
||
|
public static function nuke(): void {
|
||
|
setcookie('msz_auth', '', -9001, '/', self::domain(), !empty($_SERVER['HTTPS']), true);
|
||
|
}
|
||
|
}
|