Or any other method, for that matter.

I'm trying to create a setcookie string that will place ".domain.com" as the domain, domain.com being whatever being whatever domain the script has been installed on.

$_SERVER['SERVER_NAME'] gets me a server name with whatever subdomain is at the front. I'd like to make sure I end up with only ".domain.com".

How can I make this happen?

Thanks for your time!

    Might you have to deal with domain names like "seit.unsw.adfa.edu.au", "eclipse.gsfc.nasa.gov" or "europa.eu"? Which bit would you call the domain name and which bit the subdomain? If it's something like "the highest-level component over which the registrant has control" then you'd end up wanting something like the Public Suffix List to identify how much the registrant doesn't control.

      Hi there and thanks very much for your help.

      I'm not quite good enough at this stuff to know how I would implement the content in your link. The only thing I'm hoping to be able to do is to make sure that the cookie I'm setting will work whether they're getting to the page via www.domain. com, domain.com or somethingelse.domain.com. PHP manual states that to do this, I need to use ".domain.com" in the cookie details. My hope was to manipulate the _SERVER var to end up with the domain without any www or other in front of it.

      Is there a way to do this?

        The quick and dirty solution might be to grab $SERVER['HOST_NAME'], and strip any leading "www." and then prepend a dot, but I wouldn't guarantee it to work correctly in all possible situations.

        $dotDomain = preg_replace('/^(www)?\./i', '.', $_SERVER['HOST_NAME']);
        

        (untested)

          Write a Reply...