.htaccess tutorial

htaccess Elite


Sending POST request with CURL

Using PHP in and with htaccess

Sending POST request with CURL

New postby produke » 21 Feb 2007 21:49

It is a very handy thing to be able to send POST data from a form to a script. Normally you would do this using a form on an XHTML page like
Code: Select all
<form action="/cgi-bin/form-control.php" method="post">
<input type="hidden" name="secretvar1" vale="date123" />
</form>

This would send the POST data secretvar1=date123

To do the same thing from php using curl you can use this code.

Code: Select all
function Relay_Post($Post_Url){
    $Curl_Session = curl_init($Post_Url);
   curl_setopt ($Curl_Session, CURLOPT_POST, 1);
    curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "Name=$CLN_Name&Email=$CLN_Email&Message=$CLN_Message&FormName=$CLN_Form_Name&CallBack=$CLN_CallBack&CallNumber=$CLN_CallNumber&CallTime=$CLN_CallTime");
    curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);
    curl_exec ($Curl_Session);
    curl_close ($Curl_Session);
   
   return;
}



This sends the variables Name=$CLN_Name&Email=$CLN_Email&Message=$CLN_Message&FormName=$CLN_Form_Name&CallBack=$CLN_CallBack&CallNumber=$CLN_CallNumber&CallTime=$CLN_CallTime to the $Post_Url
User avatar
produke
 
Posts: 242
Joined: 25 Sep 2006 04:48

Return to PHP and htaccess