IT Community - Software Programming, Web Development and Technical Support

How to send variables from a PHP script to another URL, using POST without using form

This is a discussion on How to send variables from a PHP script to another URL, using POST without using form within the PHP Programming forums, part of the Web Development category; How to send variables from a PHP script to another URL, using POST without using forms and hidden variables?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-26-2007, 03:20 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Question How to send variables from a PHP script to another URL, using POST without using form

How to send variables from a PHP script to another URL, using POST without using forms and hidden variables?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-26-2007, 03:25 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: How to send variables from a PHP script to another URL, using POST without using

You can open an HTTP socket connection and send HTTP POST commands. Here is
an example :

<?
// Generate the request header
$ReqHeader =
"POST $URI HTTP/1.1\n".
"Host: $Host\n".
"Content-Type: application/x-www-form-urlencoded\n".
"Content-Length: $ContentLength\n\n".
"$ReqBody\n";

// Open the connection to the host
$socket = fsockopen($Host, 80, &$errno, &$errstr);
if (!$socket)

$Result["errno"] = $errno;
$Result["errstr"] = $errstr;
return $Result;
}
$idx = 0;
fputs($socket, $ReqHeader);
while (!feof($socket))

$Result[$idx++] = fgets($socket, 128);
}
//-------------------------------------------
?>


Or you can use the cURL extensions for PHP (cURL and libcurl). Once you build it and compile their support into PHP, it is fairly easy to do posting stuff (even over https):


<?
$URL="www.mysite.com/test.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://$URL");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "Data1=blah&Data2=blah");curl_exec ($ch);
curl_close ($ch);
?>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the Post values without using Server Variables? senraj PHP Programming 6 10-17-2007 11:31 PM
How to send data from servlet to javascript variables Pvinothkumar HTML, CSS and Javascript Coding Techniques 0 10-09-2007 11:05 PM
How to select a value from a child form and send it to parent form? GDevakii ASP and ASP.NET Programming 1 09-20-2007 10:14 PM
How can I send variables from a PHP script to another URL using POST without using fo kingmaker PHP Programming 2 07-24-2007 02:58 AM
How to Send Email from a PHP Script Using SMTP Authentication? Sabari PHP Programming 1 07-20-2007 05:42 AM


All times are GMT -7. The time now is 02:35 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0