I need to make a script where it would remove the subdomain from $_SERVER['SERVER_NAME'] to use it on the domain option of the setcookie function to allow the access of the cookie on all possible subdomains.
For example, let's say I have
function strip_out_subdomain($domain)
{
//do something to remove subdomain
return $only_my_domain;
}
$domain = strip_out_subdomain($_SERVER['SERVER_NAME']);
setcookie('mycookie', '123', time()+3600, '/', $domain);
The main problem here is I don't know the pattern for my domain. It could be something like:
- www.mydomain.com
- subdomain.mydomain.com
- subdo.mydo.co
- subdo.subdo.mydomain.com
- subdo.subdo.mydo.co.uk
- etc.
Thank you
Stephanie