Log in

View Full Version : C++ and PHP - code needed to share data



C0ldf1re
03-10-2010, 10:34 PM
I have data on a desktop PC used by programs written in C++.

I have data on a website used by scripts written in PHP.

How can I link the two of them to share/update/check data?

djr33
03-11-2010, 01:44 AM
You would need to store the data in an external location both can reach.
The obvious answer is a database, but you can also use text files if for some reason that works better.

The exact setup depends on how you want them to interact (for example whether they are on the same computer), how you can setup connections between the two (effectively both will need to access the same server, which could also contain one or both programs), and what your goals with the programs are.

Note that PHP is different from C++ in that PHP remains as code that is processed and C++ is first compiled then run as an .exe, so that this means you will need to rewrite the C++ then compile it in the new format and do that every time you update the system (or the PHP if that affects the system).

C0ldf1re
03-13-2010, 06:35 PM
Thanks. I should of course have explained the problem in more detail!

A desktop is running a back-office accounts system written in C++ using a DBF database. This setup cannot be fundamentally changed, but we can amend the code. (We cannot even try to put all our accounts on the web; that is forbidden by the company for security and reliabilty reasons.)

A new webstore has been installed on a website hosted on the net with a third-party webhost. This is written in PHP using a MySQL database. The code is open source and we can amend it. (We cannot try to host the webshop on our desktop machine, or not unless someone can convince us that it is reasonably easy to do, and likely to be secure and reliable!)

We need the C++ back-office system to be able to tell the webstore about e.g. new stock received. At present staff need to enter the data both into the back-office and into the webstore manually.

We need the back-office to be able to know about the webstore's new customers, sales and payments received. At present the webstore sends emails to the office, who have to re-enter the data into the C++ system.

We have never done anything like this before, so we need a pointer in the right direction. Our guess is to write code so the C++ system can send and receive messages to the webstore. We have heard about things like SOAP, but we need guidance about finding C++ and PHP modules that we can incorporate. Or we might be guessing wrong.

If someone who KNOWS can tell us which way to go, it would save us a lot of time and we would be very gratefu!

djr33
03-14-2010, 06:26 AM
There's a paradox:
1. You can't get access to the secured data.
2. You need access to the secured data.


There are two ways to do this:
1. Host the website from the C++ computer, and get access locally through the filesystem. Easy in that sense, hard to setup and perhaps even a security risk (if the server is hacked, so is the rest of your data).
2. Allow the data from the C++ computer to be accessed remotely by PHP. This also presents a security issue: outside computers can get access. However, you could restrict by IP so that only your server can get access.


The bottom line here is that you must figure out a way to make the two talk to each other, and that's beyond any questions about code. There's probably a way to make code for any setup you need, but you DO need to allow the data to be sent back and forth.

You're going to need to compromise at least one of the approaches (C++ or PHP) and recode at least one as well.
It looks like PHP will be easier in a few ways, so that's fine-- but that means you also need to make the data from the C++ computer available to the PHP.


The only other way to go about it would be to connect the C++ computer to a remote database that would mirror the local information that could then be seen by PHP. But this is not really any more secure than just moving the C++ database to a remote location in the first place... not sure about what the benefit would be.


I believe that in the industry the standard way to do this IS to move the database to a remote location that can then be accessed by both. This can be a server on a network, for example, or on the internet. It really depends on your needs. But the simple answer here is that: 1) there is no simple answer; 2) you need to allow access to the data from both, and this means compromising security (though you can compensate) and connecting the two computers to a single data source, somehow.


Honestly, if you aren't sure how to do this I would suggest hiring someone who does this stuff, because this is a complex job with big security concerns and it's unique to your situation. There's no textbook answer for it.

C0ldf1re
03-15-2010, 07:13 AM
Thanks for the advice.

Actually it is a help to have someone confirm that there is no "good" solution.

djr33
03-15-2010, 02:09 PM
Yes, consider it confirmed then.
It's not impossible to make this system work, but it would require some big changes and making the system secured after adding some possible vulnerabilities, not that this is very different from lots of websites [in a general sense].

The way I'd suggest going about this is to use the C++ computer as a server and allow data to be accessed remotely only from the PHP server (by IP address, and/or maybe a password stored on the server never visible to the public, used to confirm the identity of the request).
In theory that's all you need, but it still requires a lot of setup, as described above.


Of course the 'easiest' way is to just set everything up differently than what you have, for example using the same language and same server for both processes, but I understand why that is now difficult.