Sending a GET request to sever with C client and printing request on PHP webpage

534

I have searched online for loads of tutorials on sending a GET request in C to the server. I have been successful in sending the get request but I would like to print the request on the index.php page hosted on the websers. For example, i will run the C client, and the request will then be displayed on the web page that was sent from the C client. Where would I start in terms of the PHP? I am good with PHP and databases, im not just sure when it comes to connecting it to an outside program.

For example, making a GET request containing a parameter. When the GET request is sent to the server and the parameters is stored in the MYSQL database and I can then display that parameters from the database using SELECT etc... I know it's possible I'm just not sure how to pass the parameters into the PHP so I can then do an INSERT INTO database.

Anyhelp would be great and here is my current C client.

/* windows client */

#include <stdio.h>
#include <winsock.h>

#pragma comment(lib,"ws2_32.lib")

int main(int argc, char *argv[]){

    WSADATA wsa;
    SOCKET s;
    struct sockaddr_in server;
    char *message;

    printf("winsock starting.......\n\n");

    if(WSAStartup(MAKEWORD(2,2),&wsa)!=0){
        printf("ERROR CODE:", WSAGetLastError());
        return 1;
    }
    printf("winsock all good\n\n");

    if((s=socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET){
        printf("bad socket", WSAGetLastError);
    }
    printf("good socket\n\n");

    server.sin_addr.s_addr = inet_addr("127.0.0.1");
    server.sin_family = AF_INET;
    server.sin_port = htons(80);

    if(connect(s,(struct sockaddr*)&server, sizeof(server)) < 0 ){
        puts("bad connection");
        return 1;
    }
    puts("good connection");

     //Send GET data
    message = "GET / HTTP/1.1\r\n\r\n";
    if( send(s , message , strlen(message) , 0) < 0)
    {
        puts("Send failed");
        return 1;
    }
    puts("Data Send\n");

    return 0;
}

People are also looking for solutions to the problem: echoing to text box in php

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.