Alright so We have a simple PHP-File on my server that echo's back a version-number. When the builder is ran, it checks if the Version from the PHP-File is the same as the version-number hardcoded in the builder, if not it replaces itself with the new download (Which is on my server aswell) How could I put this in my C++ code? Thanks for any help.
-
Do you have access to the actual php file? Or do you only have access to its output? – Ove Feb 15 '14 at 20:13
-
Currently the php file is on my friends dedicated server so he put me in charge of the coding part. http://tastylico.us/WlpfdmHGc4/zero.php – user3314284 Feb 15 '14 at 20:15
-
Do you run your program on the web server? Or do you run your program on a client that needs to check the server? – Ove Feb 15 '14 at 20:16
-
Friend gave me this example: – user3314284 Feb 15 '14 at 20:22
-
Dim wc As New Net.WebClient Dim v As String = wc.DownloadString(www.tasty.de/zero.php) Dim MyVersion As String = My.Settings.Version If v = MyVersion Then wc.DownloadFile(www.tasty.de/Builder.exe) End If – user3314284 Feb 15 '14 at 20:22
-
I think I know what you need, I will type out an answer shortly – Ove Feb 15 '14 at 20:23
-
Thanks, will help me out alot! – user3314284 Feb 15 '14 at 20:24
1 Answers
You need to download the output of the php script on the client PC and parse the text to get the version number.
To do this, you need to use a library that allows you to download a page from the internet. This is just like getting the html output of a web page (eg. for google.com)
I don't know what platform you are using, but here are some libraries you can use to download a file from the internet:
- libcurl
- URLDownloadToFile if you are using Windows
You can find libcurl examples here: Download file using libcurl in C/C++ and [C/C++] How To Get The HTML Of a Web Page
You can find a URLDownloadToFile example here: How to download HTML with C++
For the URL you should use the path to the php file on your server (eg. "www.tasty.de/zero.php"
)
You can save the output to a temp file on the disk (or maybe even keep it in memory) and then you have the version string. From there it's straightforward to parse the version number out of the string.