|
-
September 18th, 2004, 05:38 PM
#4
You would have to open a direct connection with the server you would want to connect to, and manually send the HTTP POST request containing the variables.
Here's a small function which should be able to handle this.
Code:
function post_page($host, $path, $post_data)
{
// Opens a connection to the server
$fp = fsockopen($host, 80, &$error_number, &$error_string, 120);
// Trigger an error if we failed to connect, else continue
if (!$fp)
{
trigger_error('Connection error: ' . $error_string . ' (' . $error_number . ')', E_USER_ERROR);
return FALSE;
}
// See how many bytes our POST data is
$data_length = strlen($post_data);
// Send our HTTP POST request to the server
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: $data_length\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $post_data);
// As long as the server returns data, keep getting it in 1k chunks
$output = '';
while(!feof($fp))
{
$output .= fgets($fp, 1024);
}
// Close the connection
fclose($fp);
// Return any data returned by the server
return $output;
}
The above function accepts 3 variables. The $host variable should contain the hostname of the server, ie "www.example.com" or "example.com" without the protocol or leading slash. The $path variable should contain the path to the script you want the data to be posted to. For instance, "/foo/bar/script.php" or "/cgi/process_this.cgi". Finally, the $post_data variable should contain a string which specifies the data you want to post. This is easier to explain by showing an example.
For instance, if you would use the following function with the following $post_data value:
Code:
variable_name=value&variable_name2=578&variable_name3=me
The script you'd contact would have access to 3 POST variables called "variable_name", "variable_name2", and "variable_name3", with the values "value", "578", and "me" respectively.
I have not tested the function, but it should work. If you have any problems, reply or PM me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|