-
September 18th, 2004, 10:33 AM
#1
Junior Member
How can I send variables from a PHP script to another URL?
Hello,
Please tell me How can I send variables from a PHP script to another URL using POST without using forms and hidden variables?
Thanks
Laxy
www.funspot.com
-
September 18th, 2004, 12:57 PM
#2
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
#3
Junior Member
Thanks MoonWolf for your quick reply i will check and get back to you............
-
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
|
|