If I point a domain (www.site.com) to a subdomain (site.cool.com), can I use a $_SERVER variable to see that the user came to the subdomain from www.site.com? I don't want the site.cool.com to ever show publicly.
Can you explain what you mean by pointing a domain to subdomain? You mean redirection? And what do you mean you don't want site.cool.com to show publicly? On google? On in web browsers' location bar?
What I mean by 'pointing' is actually going to the registrar and having that domain point to that site (with the subdomain).
And yes, I do not want the site.cool.com to show publicly (just show a blank page or redirect somewhere else), on google or the location bar.
Maybe there is a better way to do this but I basically need to figure out how the flow works...do I take the domain www.site.com and point to a dedicated IP address for the server it's going to point to and then do I need to setup an A record to point to the subdomain on my end?
The project is a website were users can create their own website using one of the pre-made templates and a small CMS. So each site will be located on a subdomain (like: drsnow.site.com or energyplus.site.com). Whatever sub-domain they choose. Then we want them to purchase their own domain name and point it to the sub domain. My problem is that the client doesn't want the subdomain site (energyplus.site.com for example) to show if they go there directly. They only want the website to show up if they go to the site from the domain they purchase (www.energyplus.com). I'm just not sure of the best way to handle that.
So you need to point both the subdomain and the purchased domain to the same server. What I would do is I would always point both of them to the same site, I would not turn the subdomain off because in certain cases when the main domain stops working for any reason (for example a user fails to renew the domain) then the subdomain is always there to be used. Once it's set up like this then it's just a matter of creating a redirection from the subdomain to the main domain. For Apache servers you can do it easily in a .htaccess file in each site's subdirectory or in the main Apache config file (by searching it's easy to find examples like this).
Then you can even provide users with an option to turn on and off the redirection, which would result in your system simply creating or deleting the redirection directives in the .htaccess file.