Post Data to URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rkatl
Forum Newbie
Posts: 17
Joined: Tue Apr 22, 2008 8:20 pm

Post Data to URL

Post by rkatl »

I have been trying to post data to a URL (https) but no luck. I'm using the following function.

Wondering if anything is wrong in this. Anyone can help ?

function post($data) {

$host = 'www.xxxxxxx.com';
$path = '/test/testform';
$http_response = '';
$content_length = strlen($data);
$fp = fsockopen($host, 443,$errno, $errstr);
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: $content_length\r\n");
fputs($fp, $data);
fputs($fp, "Connection: close\r\n\r\n");
while (!feof($fp)) $http_response .= fgets($fp);
fclose($fp);
echo " hello...< $http_response ...> $data";
echo " ... $errno ... $errstr ...";
return $http_response;
}
User avatar
Mds
Forum Contributor
Posts: 110
Joined: Tue Apr 22, 2008 8:56 pm
Contact:

Re: Post Data to URL

Post by Mds »

I think this is best way for your purpose :

create HTML form and then submit it . (with javascript and php)
rkatl
Forum Newbie
Posts: 17
Joined: Tue Apr 22, 2008 8:20 pm

Re: Post Data to URL

Post by rkatl »

not sure what you mean using javascript & php. I have very huge form which I validate and post it using a function.

If you have a sample with javascript could you please share.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Post Data to URL

Post by John Cartwright »

I certainly would not rely on javascript for this. Take a look at cURL, or Snoopy
Post Reply