Posted by christothetopher on March 25, 2011 at 3:31pm
I've written a custom services module that is used by both android and iphone clients. Each of these clients have their own domain, android and iphone respectively.
Now, I've never had a reason to know which was making requests to the module until now (I have to give different stream URLs for different clients). So, my question is how do I access the domain being used in the request within my services module?
Any and all help greatly appreciated.
Thanks!
Comments
$_SERVER variable
As idea please look at you $_SERVER variable. You can do that with adding watchdog in your callback like
watchdog('server_var', var_export($_SERVER, TRUE));
Maybe you can find the current domain there. But this is only idea to look at. So please test.
$_SERVER
Thanks for the suggestion, unfortunately it won't be available in $_SERVER but your suggestion made me think of $GLOBALS. I tried to var_export GLOBALS and it errored out 500 in services but it's actually a recursion error due to GLOBALS being a global itself. see: http://php.net/manual/en/reserved.variables.globals.php
I also tried $GLOBALS['domain'] as well as $domain, both not being set.
I don't want to rule it out but I don't see a way to determine the domain used within services modules. What a huge bummer, I guess I'll have to dig through the services code and see what I can find.
Two suggestions: 1. Try to
Two suggestions:
1. Try to look at the Deploy module. It copies data from one site to another using services so might have some clues. I haven't used it, though, so no promises ...
2. I think the domain is held in the services_keys DB table, so if you use key authentication and can get the current key then you could query the DB for the domain. Now, I'm really not sure how to get the key, but wanted to suggest another direction to look at.
Good luck,
Micah
More helpful, hopefully
Took a look at the code and tested the following. If you're using API keys, you can put in your custom services methods this code:
$kid = services_keyauth_get_kid();
$key = services_keyauth_get_key($kid);
$key will point to an object with the following key/value pairs:
[kid] => "API key"
[title] => "Application title you provided"
[domain] => "Domain you specified for this key"
HTH,
Micah
Thanks
Exactly what I needed, thank ya sir.