This small code might help someone with a little php/sfml coding. Would it fit in the wiki?
main.cpp
#include <SFML/Network.hpp>
#include <iostream>
using namespace std;
sf::IPAddress mMyIP;
string mStringDomain = "http://www.yourdomain.com";
string mStringURI = "/ip.php";
int getMyIP()
{
sf::Http Http;
Http.SetHost(mStringDomain);
// Prepare a request to retrieve the index page
sf::Http::Request Request;
Request.SetMethod(sf::Http::Request::Get);
Request.SetURI(mStringURI);
sf::Http::Response Page = Http.SendRequest(Request);
if(Page.GetStatus()==200)
{
mMyIP = Page.GetBody();
if(mMyIP.IsValid() == true)
{
cout<<"My IP: "<<mMyIP.ToString()<<endl;
return 1;
}
else
{
cout<<"The ipadress retrieved was not valid."<<endl;
return -1;
}
}
else
{
cout<<"Could not connect."<<endl;
return -2;
}
}
int main()
{
getMyIP();
// Wait until the user presses 'enter' key
std::cout << "Press enter to exit..." << std::endl;
std::cin.ignore(10000, '\n');
return EXIT_SUCCESS;
}
ip.php
<?php
echo $_SERVER['REMOTE_ADDR'];
?>