Page 1 of 1

Delegating database queries to another Server/Website?

Posted: Tue Aug 23, 2011 9:36 am
by leonb
Hi,
i'm new here and first I beg you to excuse my not so perfect english. Also if this posting is in the wrong section of the forum, please move it where it belongs.
So here's my problem with which I hope you can help me. The scenario is as follows:
1. I have a main website (let's call it mainsite from now on), On that server, I have a MySQL database which has a table with items to buy and a table with registered users. There's a registering and login mechanism allready implemented.
2. On another server (let's call that shopserver from now on) I want to set up a shop for buying and downloading items. I have this server, because it is quite cheap and I have loads o webspace there.
3. Shopserver is accessible via a subdomain of mainsite, which is shop.mainsite.com.

What I want to accomplish is:
1. Visitors should not be forced to use a separate login on shopserver
2. I dont want to duplicate the database (user- and itemtable) on shopserver, because I would have to maintain 2 seperate databases which calls for trouble.
3. Instead I want shopserver to use the database on mainsite.

I accomplished 1. by setting the domain parameter of setcookie to .mainsite.com so the subdomain gets the login cookie also
What I am looking for now, is a way that if a user logs in on the shopserver, a script on shopserver calls a script on mainsite which checks the login and tells shopserver, if the login is ok.
I also want the possibility, that a scrip on shopserver can call scripts on mainsite, if a logged in user, for example, buys an item on shopserver. The called script on mainsite should then handle the required database calls on mainsite and tell shopserver, if the purchase could be processed etc.

This is not a very big enterprise, so I am looking for a small & easy solution, this means, whenever possible I want to avoid complicated stuff... IF possible.

What I thought about as a solution is that, for example, the login form on shopserver has a script like mainsite/login.php as the POST action. BUT: I fear that this is a not very secure solution AND posting a form has no possiblity, that mainsite/login.php returns a login result to shopserver.

I hope you understand what I described in my dodgy english.

Thanks in advance
Leon

Re: Delegating database queries to another Server/Website?

Posted: Tue Aug 23, 2011 11:27 am
by greip
There are at least two approaches to solve this:

1) Create a set of web services on the main server which can be used by the shopserver to validate user credentials, register purchases, etc. Use JSON or XML for data sent between the servers.

2) Configure the database server on your main server so that PHP scripts on the shopserver can connect to it. Scripts on the shopserver can then do the necessary lookups and alternations in the database directly.

For both approaches you need to make sure that only the shopserver can connect to the mainserver and that no-one can listen in on the communication between the servers.