Alt-PHP-Faq
Cheapest CO.UK domains in the UK! £1.88 per year!
And PHP/MySQL hosting 1p/1c for the first month, NO CATCH!


Question :

How can I send variables from a PHP script to another URL using POST without using forms and hidden variables?

Answer :
You can open an HTTP socket connection and send HTTP POST commands. Here is
an example :

<?
// Generate the request header
$ReqHeader =
"POST $URI HTTP/1.1\n".
"Host: $Host\n".
"Content-Type: application/x-www-form-urlencoded\n".
"Content-Length: $ContentLength\n\n".
"$ReqBody\n";

// Open the connection to the host
$socket fsockopen($Host80, &$errno, &$errstr);
if (!
$socket)

$Result["errno"] = $errno;
$Result["errstr"] = $errstr;
return 
$Result;
}
$idx 0;
fputs($socket$ReqHeader);
while (!
feof($socket))

$Result[$idx++] = fgets($socket128);
}
//-------------------------------------------
?>


Or you can use the cURL extensions for PHP (http://curl.haxx.se). Once you build it and compile their support into PHP, it is fairly easy to do posting stuff (even over https):


<?
$URL
="www.mysite.com/test.php";
$ch curl_init();   
curl_setopt($chCURLOPT_URL,"https://$URL"); 
curl_setopt($chCURLOPT_POST1);
curl_setopt($chCURLOPT_POSTFIELDS"Data1=blah&Data2=blah");curl_exec ($ch);    
curl_close ($ch);
?>


This will have the net effect of posting your data to the $URL site, without any header hacking.

You can also do other nifty things with cURL, like retrieve the HTML into variables and scrape through it for neat functionality.

To use cURL you need to recompile PHP or check with your ISP to see if they support it (http://www.php4hosting.com does)



Categories Return to Main PHP Faq

Code

 

Questions

Code
How do I get a user's IP address?
How do I generate a random number from php?
How do I insert javascript in php code?
How can I create thumbnails using PHP?
Can I create PDF files from php?
Is it possible to send HTML mail with php?
How can I use PGP with PHP?
I keep getting "headers already sent" whilst trying to use sessions
How do I format a number correctly?
How do i upload files from php to my ISP / server?
How do I user authentication in php?
How do I set the browser timeout?
How can I create random passwords?
Is there a way to encrypt text from php?
How can I limit search results so that there is a "Next 10" and "Previous 10"?
How can I protect pages using MySQL and PHP?
How do I check whether a string contains HTML?
How to count number of parameters given in URL by POST?
How do I find out weather a number is odd or even?
Is it possible to spell check texts from php?
Does anyone know some URLS for good tutorials on PHP?
How to output a number with leading zero's?
How do I get the total size of a certain directory?
How can I do error handling in php?
What's the difference between the *connect and *pconnect database functions?
How do I work with dates in php?
How to access a COM object from within my PHP page?
How can I get the DNS servers of a domain name?
Is it possible to validate an e-mail in php?
Is it possible to connect to a ftp server with php?
How do I make links on mail and www links on my pages?
I keep getting "Data Missing" when I click the "back" button in my browser. How can I stop this?
How can I mail the content of a form?
Using Curl can I access the OpenSRS admin control panel (tucows)
I have an array of values and want to show them all reccursivly how?
Use ereg_replace to replace only the first occurence of a string instead of all?
How do I find out if an array has values posted to each of its elements? I need to know that EVERY element has been filled out.
How do you colour code the source in the answers on alt-php-faq.org?
I have upgraded to PHP-4.0.5, since doing that some of my scripts are just showing the source code?
 

Return to the main FAQ list



Free Forum    
Design & Layout Copyright © 2000- 2006 PHP MySQL Web Hosting Comments to Webmaster
Hosted by PHP 4 Hosting - PHP and MySQL Webhosting and Domain Names