Hi, I am trying to read a webpage, namely a PHP page that returns "true" or "false" depending what $_GET (Or is it $_POST?) information is sent. The URL it attempts to read will look like this: www.thesite.com/key.php?key=the_key and the page will return a true or false. I currently have this code:

//Web page reader? possibly...

#include <iostream>
#include <fstream.h>
#include <string.h>
using namespace std;

int main() {

     int key;
     string answer;
     string url;
     ifstream infile;
     
     cout << "Enter your key: " << endl;
     cin >> key;
     url = "http://thesite.com/key.php?key=" + key;
     

     infile.open(url);
     if(!infile.is_open(){
                          cout << "Cannot open file" << endl;
                          system("pause");
                          }
     
     while (getline (infile, answer))
     
     if(answer == "false") {
               cout << "Invalid key." << endl;
               cin.get();
               system("cls");
               main();
               }
     if(answer == "true") {
               cout << "Correct!" << endl;
               cin.get();
               return 0;
               }
     else {
          cout << "Hmm... idk why it did that..." << endl;
               cin.get();
               system("cls");
               main();
               }   
     
     cin.get();
     return 0;
}

I am sure I am doing something totally wrong, I have read about a lib called CURL, I'm not sure if that will do the job, and also something about piping wget output. If anyone could explain these or point me to a tutorial, it would be greatly appreciated!

--Dylan

If this problem seems like something too big to chew, can someone suggest a language that could solve this problem easier? Possibly with the option of at some point making it GUI?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.