In general, I am a beginner in PHP, I used to have such a script (I wrote a book), but I lost it. Help to do this simple thing. There is a website:

site.com/test/test2/index.php?action=send_s&msisdn=тут_текст&from=тут_второй_текст&msg=тут_третий_текст&submit=Send

It is necessary to do so that I can send the form from my site, but at the same time send a request to that site. And that site should not be displayed at all.

  • > It is necessary to do so that I can> send the form from my site, but> at the same time send a request to that> site .. And that site should not> be displayed at all You read what you wrote yourself? - Kenpachi
  • I do not know how to explain .. you need to make a php-form and access that site, but stay on my site - JavaBitz

2 answers 2


 <? $data="var=test&var2=privet"; $fp = fsockopen("test.ru", 80, $errno, $errstr, 10); $out = "POST /file.php HTTP/1.1\n"; $out .= "Host: test.ru\n"; $out .= "Referer: test.ru/\n"; $out .= "User-Agent: Opera\n"; $out .= "Content-Type: application/x-www-form-urlencoded\n"; $out .= "Content-Length: ".strlen($data)."\n\n"; $out .= $data."\n\n"; fputs($fp, $out); fclose($fp); ?> 

Still

 <? $url = "http://test.ru/patch/file.php?var=23&var2=54"; // это адрес, по которому скрипт передаст данные методом POST. Как видно, здесь указаны переменные, которые будут переданы через GET $parse_url = parse_url($url); // при помощи этой функции разбиваем адрес на массив, который будет содержать хост, путь и список переменных. $path = $parse_url["path"]; // путь до файла(/patch/file.php) if($parse_url["query"]) // если есть список параметров $path .= "?" . $parse_url["query"]; // добавляем к пути до файла список переменных(?var=23&var2=54) $host= $parse_url["host"]; // тут получаем хост (test.ru) $data = "var3=test&var4=".urlencode("еще тест"); // а вот тут создаем список переменных с параметрами. Эти данные будут переданы через POST. Все значения переменных обязательно нужно кодировать urlencode ("еще тест") $fp = fsockopen($host, 80, $errno, $errstr, 10); if ($fp) { $out = "POST ".$path." HTTP/1.1\n"; $out .= "Host: ".$host."\n"; $out .= "Referer: ".$url."/\n"; $out .= "User-Agent: Opera\n"; $out .= "Content-Type: application/x-www-form-urlencoded\n"; $out .= "Content-Length: ".strlen($data)."\n\n"; $out .= $data."\n\n"; fputs($fp, $out); // отправляем данные // после отправки данных можно получить ответ сервера и прочитать информацию выданную файлом, в который отправили данные... // читаем данные построчно и выводим их. Конечно, эти данные можно использовать по своему усмотрению. while($gets=fgets($fp,2048)) { print $gets; } fclose($fp); } ?> 

In this example, the file file.php got the variables:

GET var = "23" and var2 = "54"

POST var3 = "test" and var4 = "another test"

  • Thank you very much, but I need the user to fill out the form from my site, and she went to that one .. how to implement it? - JavaBitz
  • <form method = "POST" action = "" name = ""> var1: <input type = "text" name = "var1" /> <br> var2: <input type = "text" name = "var2" / > <br> <input type = "submit" id = "call" name = "subm" value = "send" </ form> the data you need will be in the variables $ _POST ['var1'] and $ _POST ['var2' ] send them away. - Kenpachi

you decide you have a GET or POST request?

 <form method="POST" action="http://site.com/test/test2/index.php" name=""> 

and insert all the fields from that form and send a request if GET <form method = "GET" action = "http://site.com/test/test2/index.php" name = "">