PHP kullanarak bir form gönderme

4 Cevap

Ben bir yöntem POST formu gönderme, otomatik olarak bu formu gönderebilirsiniz bir senaryo yazmak istiyorum, ben bu yüzden ihtiyacımız test amaçlıdır. Ben bu form alanlarına dayalı bir arama test etmek için biraz zaman çok fazla veri gerekiyor ve ben mannulally bunu yapmak için zaman yok. Bu mümkün mü?

4 Cevap

Siz formu gönderin simüle etmek kıvırmak kullanabilirsiniz.

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/script.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true ); //enable POST method

// prepare POST data
$post_data = array('name1' => 'value1', 'name2' => 'value2', 'name3' => 'value3');

// pass the POST data
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data );

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

Source:http://php.net/manual/en/book.curl.php

eğer curl kullanarak bir web tarayıcısı taklit snoopy adında bir php kütüphanesi kullanabilirsiniz rahat değil. Bu web sayfası içeriği almak ve formları gönderme görevi otomatikleştiren.

<?php
/* load the snoopy class and initialize the object */
require('../includes/Snoopy.class.php');
$snoopy = new Snoopy();

/* set some values */
$p_data['color'] = 'Red';
$p_data['fruit'] = 'apple';

$snoopy->cookies['vegetable'] = 'carrot';
$snoopy->cookies['something'] = 'value';

/* submit the data and get the result */
$snoopy->submit('http://phpstarter.net/samples/118/data_dump.php', $p_data);

/* output the results */
echo '<pre>' . htmlspecialchars($snoopy->results) . '</pre>';
?>

PHP verilerle formunu doldurmak izin ve mesaj formu, PHP kendi-sen bunu açamazsınız bir Javascript çıktı.

PHP ile POST istekleri göndermek için php.net / curl kullanabilirsiniz.