Sending variables as post

Discussion in 'PHP' started by moso, Aug 24, 2007.

  1. #1
    I need a script to send some variables as post. Basically I need to replicate a form that sends values with method post. No need for login, cookies or something else.
    I will appreciate any help.
     
    moso, Aug 24, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    nico_swd, Aug 24, 2007 IP
  3. DKameleon

    DKameleon Member

    Messages:
    29
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    38
    #3
    Hope it's what you need :)
    
    			function format_post($data) {
    				$result = "";
    				foreach ($data as $k => $v) {
    					$result .= "&".urlencode($k)."=".urlencode($v);
    				}
    				return substr($result, 1);
    			}
    
    
    				$ch = curl_init();
    				curl_setopt($ch, CURLOPT_URL, $url);
    				curl_setopt($ch, CURLOPT_POST, 1);
    				$params = array(
    					"a" => $a,
    					"b" => $b,
    				);
    				curl_setopt($ch, CURLOPT_POSTFIELDS, format_post($params));
    
    				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    				curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    				$result = curl_exec($ch);
    				curl_close($ch);
    
    
    PHP:
     
    DKameleon, Aug 24, 2007 IP