|
|
|
Let's ask this question in a different way.
Let's say that I'd like to submit any form on the net... the only way to do
it is:
1) Connect there using a browser;
2) insert infos in the form;
3) click the submit button.
Imagine, that I'd like to do it in a "batch mode" (for example, inserting
infos in a searching engine, without human support, maybe "crontab-ed" :-)
)...
The question could be: "is there a way to submit a form (POST form) using
PHP3 to emulate a browser connection, sending all the values for the form
fields, and of course, emulating the click on the submit button?"
Sure... :
function PostToHost($host, $path, $data_to_send) {
$fp = fsockopen($host,80);
fputs($fp, "POST $path HTTP/1.1\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: ".strlen($data_to_send)."\n");
fputs($fp, "Connection: close\n\n");
fputs($fp, $data_to_send);
while(!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
You would call this function with something like:
PostToHost("www.whatever.com","/cgi-bin/whatever.cgi","abc=123&def=456");
Note that the data is encoded the same way you encode stuff when you put
it in a url. You can use PHP's url_encode function for this if you want,
or just do it manually like I did here.
The function also echos back the result. You can of course choose not to
do that if you want.
|
|
| PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | Alternating background color for HTML table rows Categories : PHP, Databases, MySQL, HTML and PHP | | | Constantly refresh your PHP/HTML page data. Categories : PHP, HTML and PHP, Sybase | | | background music script for random notes in a frame Categories : PHP, Content Management, HTML and PHP | | | A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | | | PhpView 0.1 - simple php viewer, using temporary files and frames.
Categories : PHP, PHP Options and Info, Debugging, HTML and PHP | | | Automatically printing the contents of an sql table in MySQL. Categories : MySQL, PHP, HTML and PHP, Databases | | | PHP template processing Categories : PHP, Templates, HTML and PHP | | | XDT Topsite (Gold v1.0) Categories : Databases, CSS, PHP, HTML and PHP, Sessions | | | function textwrap will wrap text to any desired width using <BR>\n as the default line break.
Default wrap width is 80 columns.
Categories : Strings, HTML and PHP, PHP | |
|
|
|