To send data to a remote PHP script, you must send a sf::Http request, either in POST or GET mode. GET encodes the variables in the URL, while POST hides them in the request body. On the PHP side, the difference is just a matter of reading the $_POST or $_GET global variable.
Then your PHP script can answer anything, for example "ok" or "error".
sf::Http::Request request;
request.setMethod(sf::Http::Request::Post);
request.setURI("/login.php");
request.setBody("username=xxx&password=yyy"); // I let you figure out how to build this string dynamically
sf::Http Http("www.mysite.org");
sf::Http::Response response = Http.sendRequest(request);
bool ok = (response.getBody() == "ok");
The PHP script:
$username = $_POST['username'];
$password = $_POST['password'];
// sql stuff with $username and $password...
if (ok)
echo "ok";
else
echo "error";
It might not work out of the box, I just wrote this quickly to show you the right direction.
I tried your code, but I am getting strange errors which dont make a clue (to me that is lol)...
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
#include <string>
int main()
{
// message
std::cout << "Hello world!" << std::endl << std::endl;
// http request to verify username and password
sf::Http::Request request;
request.setMethod(sf::Http::Request::Post);
request.setUri("/login.php");
request.setBody("username=GroundZero&password=test");
sf::Http Http("www.site.com");
sf::Http::Response Responce = Http.sendRequest(request);
std::string result = Responce.getBody();
// let the user know if the login was accepted
std::cout << result << std::endl;
// end program
return 0;
}
QT += core gui
TARGET = project
TEMPLATE = app
SOURCES += main.cpp
HEADERS +=
LIBS += -L"C:\SFML\lib" -lsfml-window -lsfml-graphics -lsfml-network -lsfml-system
INCLUDEPATH = "C:\SFML\include"
Error messages:
The program has unexpectedly finished.
Compile output:
WARNING: c:\Users\Angelo\Desktop\Projecten\Validate Username and Password\project\project.pro:17: Unescaped backslashes are deprecated.
WARNING: c:\Users\Angelo\Desktop\Projecten\Validate Username and Password\project\project.pro:17: Unescaped backslashes are deprecated.
WARNING: c:\Users\Angelo\Desktop\Projecten\Validate Username and Password\project\project.pro:17: Unescaped backslashes are deprecated.
C:/QtSDK/mingw/bin/mingw32-make.exe -f Makefile.Debug
mingw32-make.exe[1]: Entering directory `C:/Users/Angelo/Desktop/Projecten/Validate Username and Password/project-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug'
g++ -mthreads -Wl,-subsystem,windows -o debug\project.exe debug/main.o -L"c:\QtSDK\Desktop\Qt\4.7.4\mingw\lib" -lmingw32 -lqtmaind -LC:\SFML\lib -lsfml-window -lsfml-graphics -lsfml-network -lsfml-system -lQtGuid4 -lQtCored4 -LC:\OpenSSL-Win32_full\lib
mingw32-make.exe[1]: Leaving directory `C:/Users/Angelo/Desktop/Projecten/Validate Username and Password/project-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug'
16:20:35: The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited normally.