PDA

View Full Version : ارسال اتوماتیک اطلاعات



paranoide
چهارشنبه 08 شهریور 1391, 18:21 عصر
سلام به همگی
من میخوام یه سری اطلاعات رو به صورت اتوماتیک به سرور ارسال بشه با جاوا میشه ولی با php نتونستم و میخوام با php اینکارو کنم

<form name="myform" method="post" action="mydomain.com">
<input type="hidden" name="username" value="test" />
<input type="hidden" name="password" value="test" />
<script language="JavaScript">document.myform.submit();</script></form>
</form>

سرچ زدم ولی نتونستم:متفکر::متفکر:

eshpilen
چهارشنبه 08 شهریور 1391, 19:42 عصر
در PHP با استفاده از سوکت یا cURL میشه درخواست HTTP ارسال کرد (و پاسخ رو گرفت).

paranoide
چهارشنبه 08 شهریور 1391, 20:14 عصر
در PHP با استفاده از سوکت یا cURL میشه درخواست HTTP ارسال کرد (و پاسخ رو گرفت).

میشه یه نمونه بزارید.
sample های تو اینترنت رو میزنم کار نمیکنه.

m-i-l-s-o-n
چهارشنبه 08 شهریور 1391, 20:40 عصر
92025
sample های تو اینترنت رو میزنم کار نمیکنه. مطمئن بشید cURL توی سرور شما فعاله برای این کار توی فایل php.ini باید کامنت extension=php_curl.dll رو بردارید. و یک بار سرور رو ریستارت کنین.


<?php
// in class ye browser php ba cURL hast ke emkane post va get dare cookie ro ham khodesh negah midare va modirat mikone
class Curl {

public $cookieJar = "";

// Make sure the cookies.txt file is read/write permissions
public function __construct($cookieJarFile = './cookies.txt') {
$this->cookieJar = $cookieJarFile;
}

function setup() {
$header = array();
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; // browsers keep this blank.

curl_setopt($this->curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7');
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($this->curl, CURLOPT_COOKIEJAR, $this->cookieJar);
curl_setopt($this->curl, CURLOPT_COOKIEFILE, $this->cookieJar);
curl_setopt($this->curl, CURLOPT_AUTOREFERER, true);
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
}

function get($url) {
$this->curl = curl_init($url);
$this->setup();

return $this->request();
}

function getAll($reg, $str) {
preg_match_all($reg, $str, $matches);
return $matches[1];
}

function postForm($url, $fields, $referer = '') {
$this->curl = curl_init($url);
$this->setup();
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_POST, 1);
curl_setopt($this->curl, CURLOPT_REFERER, $referer);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $fields);
return $this->request();
}

function getInfo($info) {
$info = ($info == 'lasturl') ? curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL) : curl_getinfo($this->curl, $info);
return $info;
}

function request() {
return curl_exec($this->curl);
}
}

// masln mikhaim tu ye site login konim

$curl = new Curl(); // yek instance azash misazim

$url = "http://www.tayp.ir/login.php"; // addressi ke mikhaim etelaat behesh post beshan ro minevisim

$fields = "pass=&showpage=login.php&email=hitman_sd%40yahoo.com&password=hitman&button=%D9%88%D8%B1%D9%88%D8%AF"; // ettelaati ke mikhaim ersal beshe ro minevisim. beine variable ha & mizarim beine name field va meghdaresh = mizarim

// http_referer ro taeen mikonim
$referer = "http://www.tayp.ir";

$html = $curl->postForm($url, $fields, $referer);

echo $html;


// login anjam shod hala ye safhe dge ro baz mikonim in bar get mikonim

$html = $curl->get("http://www.tayp.ir/index.php?showpage=reqs.php");


echo $html;


?>