![]() |
|
[C] C++ Client to PHP Server /// TUTORIAL & SOURCE CODE - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] C++ Client to PHP Server /// TUTORIAL & SOURCE CODE (/showthread.php?tid=6265373) |
C++ Client to PHP Server /// TUTORIAL & SOURCE CODE - Hackers - Mar 6, 2024 In this very short guide you will learn how to create a POST request from a C++ program to your website, and how to store that data to a .txt file on a server with PHP. For the client side we will use WinHTTP which can handle both http and https requests to websites. This is a much more native solution than something like curl which would require openssl or similar alongside it to do an https:// web request. Our client program is less than 20 lines of code, and all it does is just send 2 string values (something, with value of 'goes', and here with value of 'booya'). We can modify that to send string versions of any data format, or other information we need to save to the server. C++ Client Code #include <windows.h>On the server side we make use of a tmp folder that isn't accessible to the public to store our data. This is a very basic script that will save a .txt file any time there is a new request. It is set up to save GET or POST requests, but our C++ client only sends POST. It also stores something called 'REMOTE_ADDR' which is the IP address of the requesting user (the device the C++ client is on). PHP Server (your-website.com/post/receive.php) PHP Code This is a very primitive example but shows how a C++ client can send data to a PHP server to save for review later. I hope this helps you develop out your latest ideas! :) RE: C++ Client to PHP Server /// TUTORIAL & SOURCE CODE - Klonopin - Mar 6, 2024 Pretty neat post Hackers , when I go about HTTP requests I usually stick to curl for a neater and cleaner experience. both basically the same though, but curl is crossplat POST request in curl: Code #include <iostream>GET request in curl: Code #include <iostream>RE: C++ Client to PHP Server /// TUTORIAL & SOURCE CODE - Hackers - Mar 6, 2024 (Mar 6, 2024 08:45 AM)Klonopin Wrote: Pretty neat post Hackers , when I go about HTTP requests I usually stick to curl for a neater and cleaner experience. Thanks for including this - I've had trouble with curl & ssl in the past so that's why I went a different route, but definitely would rather have something cross platform & also more modern than WinHTTP lol. I'm learning Visual Studio's options currently and that's going to make it a lot easier to start using packages. G++ for whatever reason, at least on my machine, refuses to play well with OpenSSL so I am hoping Visual Studio may make it easier to do that. RE: C++ Client to PHP Server /// TUTORIAL & SOURCE CODE - Klonopin - Mar 6, 2024 (Mar 6, 2024 08:51 AM)nodes Wrote: Thanks for including this - I've had trouble with curl & ssl in the past so that's why I went a different route, but definitely would rather have something cross platform & also more modern than WinHTTP lol. I'm learning Visual Studio's options currently and that's going to make it a lot easier to start using packages. G++ for whatever reason, at least on my machine, refuses to play well with OpenSSL so I am hoping Visual Studio may make it easier to do that. If you ever have troubles including libraries and stuff in visual studio just dm me, I have a decent experience with it. i usually end up using vcpkg most of the time tbh RE: C++ Client to PHP Server /// TUTORIAL & SOURCE CODE - Hackers - Mar 6, 2024 (Mar 6, 2024 09:00 AM)Klonopin Wrote: If you ever have troubles including libraries and stuff in visual studio just dm me, I have a decent experience with it. Yeah I need to get vcpkg or similar, and I want to think about using MSVC instead of g++ I had started using cmake files as well in past but then stopped using them and have been using VS Code tasks.json or similar for build steps. |