PHP Velho Oeste 2024

http_post_fields

(PECL pecl_http >= 0.10.0)

http_post_fieldsKodlanacak veri ile POST isteği yapar

Açıklama

string http_post_fields ( string $url [, array $veri [, array $dosyalar [, array $seçenekler [, array &$bilgi ]]]] )

Belirtilen url üzerinde bir HTTP POST isteği yapar.

Tam liste için istek seçenekleri sayfasına bakınız.

Değiştirgeler

url

URL

veri

POST değerlerini içeren ilişkisel dizi.

dosyalar

POST edilecek dosyaları içeren dizi.

seçenekler

istek seçenekleri

info

İstek/yanıt bilgileri

Dönen Değerler

Başarı durumunda HTTP yanıt(lar)ı dizge olarak döner, başarısızlık durumunda FALSE değeri döner.

Örnekler

Örnek 1 - http_post_fields() örneği

<?php
$fields 
= array(
    
'name' => 'mike',
    
'pass' => 'se_ret'
);
$files = array(
    array(
        
'name' => 'uimg',
        
'type' => 'image/jpeg',
        
'file' => './profile.jpg',
    )
);

$response http_post_fields("http://gen.tr/"$fields$files);
?>

add a note add a note

User Contributed Notes 4 notes

up
5
wormholio at gmail dot com
16 years ago
To use POST to submit a form to a site which requires a cookie for authentication you put the cookie in the $options array.  Example:

<?php

$auth
="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$form_url="http://pirates.spy-hill.net/forum_reply.php?thread=663";

$message  = "RoboCodeDwarf now has the gold. \n\n";
$message .= "RoboCodeDwarf sez: [quote] " . `fortune -s` . "[/quote]\n";

$form_fields = array(
                    
'content' => $message,
                    
'add_signature' => 'add_it',
                    
'submit' => 'Post reply'  );
$form_files=array();
$form_options=array( 'cookies' => array( 'auth' => $auth ) );

$response = http_post_fields($form_url, $form_fields, $form_files, $form_options );

$n = preg_match("/HTTP\/1.1 302 Found/", $response, $matches);
if(
$n<1) echo "FAILED\n";
else    echo
"POSTED\n";

?>
up
3
thomasxholder at compuserve dot de
17 years ago
It was hard to figure out how to actually post files with this function. The "Array of files to post" is an array of associative arrays, each need the keys "name", "type" and "file". Consider this example code:

<?php
$files
= array(
    array(
       
'name' => 'somename',
       
'type' => 'text/plain',
       
'file' => $filename
   
)
);
$http_response = http_post_fields($url, $data, $files);
?>
up
-2
ya at kirilloid dot ru
16 years ago
comment to wormholio's answer:
if you use regular expression, then use it fully:
"/HTTP\/\d\.\d 302 Found/"
Some servers still can use HTTP 1.0
up
-7
dionmagnus at yandex dot ru
14 years ago
Hear is an axmaple how to arrays as POST varibles:
<?php
 
  $response
= http_post_fields('http://example.com/page.php',
                                array(
'val[0]'=>'val1', 'val[1]'=>'val2'));
 
                               
  echo
"\$response: $response\n";                               
                               
?>
To Top