September 18th, 2004, 10:33 AM
How can I send variables from a PHP script to another URL?
Please tell me How can I send variables from a PHP script to another URL using POST without using forms and hidden variables?
September 18th, 2004, 12:57 PM
I believe the point of POST is to be hidden. Maybe you are looking for GET ?
If you don't know what that is look it up in the documentation.
Since the beginning of time, Man has searched for the answers to the big questions: \'How did we get here?\' \'Is there life after death?\' \'Are we alone?\' But today, in this very theatre, you will be asked to answer the biggest question of them all...WHO LIVES IN A PINEAPPLE UNDER THE SEA?
September 18th, 2004, 01:01 PM
Thanks MoonWolf for your quick reply i will check and get back to you............
September 18th, 2004, 05:38 PM
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.
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.
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
trigger_error('Connection error: ' . $error_string . ' (' . $error_number . ')', E_USER_ERROR);
// 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");
// As long as the server returns data, keep getting it in 1k chunks
$output = '';
$output .= fgets($fp, 1024);
// Close the connection
// Return any data returned by the server
For instance, if you would use the following function with the following $post_data value:
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.