I have the following C++ program for testing purposes:
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
int len;
char* lenstr = getenv("CONTENT_LENGTH");
if (lenstr != NULL && (len = atoi(lenstr)) != 0)
{
char* post_data = new char[len];
fgets(post_data, len + 1, stdin);
cout << post_data << endl;
delete post_data;
}
}
This simply ought to get an environment variable and display it on the screen. The PHP file from which I want to invoke this function is as follows (I call this via AJAX):
<?php
$sent = $_POST['source'];
if ($sent != "")
{
echo exec("test.exe");
}
else
echo "Please enter text";
?>
Now, the question is, how do I get $sent to be fed into the C++ program as an argument to be processed in there? I've done some research on the Internet and also here on SO, but so far I keep failing.