Mattisdada Mattisdada - 2 years ago 188
PHP Question

Programmatically assessing if a domain has Google Apps or not

I used to assess whether or not a domain had Google Apps or not by doing a CURL request to "{domain}/" and checking for this string "[sign in here for the control panel]", if it had it, it had Google Apps, if it didn't than they didn't have Google Apps.

But recently Google switched to the universal login page, and it made no distinction between domains. Now this obviously breaks how I used to check to see if it had Google Apps.

Does anyone have any other work-arounds to do this?

I tried a few URL's from Google API's, but they require Auth...

NOTE: I do not wish to check via MX/TXT records, I need to check if they have Google Apps, not if they are using it. The reason for this is I had developed a Google Apps Toolkit that did a series of checks and gave the status of a domain, the old method I used to test if a domain had Google Apps was 100% accurate, every other online Google Apps tester I used was fairly inaccurate due to them checking MX records. I don't want to fall into this trap. This was very helpful for domains that used to have Google Apps but moved to another provider and want to move back to a reseller (It happens more often than you would think, I work for a reseller)

Answer Source

I have successfully figured it out!

To determine if a domain has Google Apps purchased on it, just do the following:

Do a CURL request to: "{domain}/ServiceLogin"

Search for the following string: "Sorry, you've reached a login page for a domain that isn't using Google Apps", if it contains that string, it does not have Google Apps, if it doesn't have that string than it does contain Google Apps.

An example PHP function (I'm using file_get_contents instead of CURL on this example because it is shorter, please note you will need to enable URL based locations in php.ini)

function lookupGoogleAccount($domain) {
    $url = "$domain/ServiceLogin";
    $extpage = file_get_contents($url);
    $not_gapps = strpos($extpage,"Sorry, you've reached a login page for a domain that isn't using Google Apps");

    return !$not_gapps;


Using this method even if the domain is a reseller and using a custom SSO solution it should continue to work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download