API - Allowing access to classes to scripts on other domains

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

API - Allowing access to classes to scripts on other domains

Post by greyhoundcode »

I'm after a couple of pointers here. If I wish to make a class on Domain A available to scripts on Domain B, is it possible for Domain B scripts to simply Include/Require the relevant PHP file from Domain A, or would that not work?

If not, what is the best form of communication to facilitate this? ie, is there some way for scripts on Domain B to interact with an object on Domain A - if so, I'd be interested in the links to relevant tutorials for that system.

If you could point me in the right direction it would be appreciated.

... also, to give the problem a context, the reason for wishing to do this is exercising control over who can use the class on 'Domain A' - that is, if a given client has stopped paying their subscription to use the service then the module running on their domain would no longer be allowed access to the class.

Thanks for any help. 8)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: API - Allowing access to classes to scripts on other domains

Post by alex.barylski »

is it possible for Domain B scripts to simply Include/Require the relevant PHP file from Domain A, or would that not work?
Sure it's possible I imagine you just need to use FTP wrappers in a request like:

Code: Select all

include ('ftp://user@pass/path/to/file.php')
Or something to that effect.

I wouldnt' recommend it though:

1. FTP is horribly slow.
2. You'll be sending FTP details over the wire on each request -- greatly increasing the odds of a hacker intercepting your details

I think a better approach would be to use REST or SOAP and return the data of the class in a format such as JSON or XML, etc.
Post Reply