php - Remove subdomain from $_SERVER['SERVER_NAME'] -


I have a script to use on this domain

['SERVER_NAME'] after text

where it is removing subdomains from $ _SERVER The option of the setcookie function to allow the access of cookies to all possible subdomains

For example, let's do the thing

  function strip_out_subdomain ($ domain) {// subdomain $ just return_my_domain; } $ Domain = strip_out_subdomain ($ _ SERVER ['SERVER_NAME']); SetuKi ('mukuki', '123', time (+ 3600, '/', $ domain);   

The main problem here is that I do not know the pattern for my domain. This may be something like this:

  • www.mydomain.com
  • subdomain.mydomain.com
  • subdo.mydo.co
  • subdo.subdo.mydomain.com
  • subdo.subdo.mydo.co.uk
  • etc.

    Thank you

    Stephanie

    after this There is a regex style to remove the sub-domain part from the full domain name.

    *?

    The operator matches the wildcard so that it matches the first dot to be ungreedy.

      ceremony strip_out_subdomain ($ domain) {$ only_my_domain = preg_replace ("/^(.*?)\.(.*)$/"/" target="_blank"> $ domain) ; Return only $ my_domain; }    

Comments