I want connect to page use method=post but do not use form. Ex : I have 2 file is test.html and test.php : test.html <form action='test.php' method=post> <input type='hidden' name=test1 value='xxx'> <input type='hidden' name=test2 value='xx2'> <input type='submit' value='Submit !'> Code (markup): test.php <? echo "test 1 =$_POST[test1] & test 2 = $_POST[test1]"; ?> Code (markup): When I submit form in test.html, result is : Now, I don't use form, I have file post_test.php and I want when I visit this page, it will connect to test.php and post 2 var test1 & test2 (with value can change) and display result is content of test.php page : I can use http_post_data http://us3.php.net/manual/en/function.http-post-data.php or http_post_fields: http://us3.php.net/manual/en/function.http-post-fields.php But it require install PECL extension http://pecl.php.net/package/pecl_http I can't install it in my hosting ! And about socket ? Can you help me ?? I want specific ex . . . THANKS !
You could use raw sockets, but it would be hard as you'd have to send all the right header information...
you can use fsockopen to POST function mailman($email, $subject, $message) { $fp = @fsockopen("www.somesite.net", 80, $errno, $errstr, 30); $postdata = "email=" . $email . "&subject=" . $subject . "&message=" . $message; /* salida goes out */ $salida ="POST /test.php HTTP/1.1\r\n"; $salida.="Host: www.somesite.net\r\n"; $salida.="User-Agent: PHP Script\r\n"; $salida.="Content-Type: application/x-www-form-urlencoded\r\n"; $salida.="Content-Length: ".strlen($postdata)."\r\n"; $salida.="Connection: close\r\n\r\n"; $salida.=$postdata; /* ------------ */ if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { fwrite($fp, $salida); while (!feof($fp)) { $d = fgets($fp); //echo $d; } } } PHP:
You can try using CURL (this was mentioned above). Here is the documentation (from php.net): us2.php.net/manual/en/ref.curl.php (sorry can't link) (To my knowledge most hosts have this enabled.) Here is an example: // Your POST fields "name" => "value" $data = array("test1" => "xxx", "test2" => "xx2"); // Curl Usage $ch = curl_init(); // Open which page to send post variables? curl_setopt($ch, CURLOPT_URL, "http://www.url.com/postform.php"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); echo $output; // Lets print our results PHP: