Reply to Re: Filling out forms remote

Your name:

Reply:


Posted by Csaba Gabor on 06/03/06 08:49

Radium wrote:
> Is it possible to fill out a form on an foreign website.
> E.g. is it possible to fill out the google form from a php script
> and then initialize the search?

Two appoaches that you can take:
1. The standard way is using http://php.net/curl and friends: You
could examine the html for the page and then manually construct the
string for the form that you wish to submit. The page examination may
either be done beforehand to determine its form (as with google, whose
requirements are straighforward) or on the fly (if there is information
the server sends that needs to be returned). This approach will break
if the page in question relies on javascript.

2. If you are on windows, you can use http://php.net/com: You can
bring up a copy of InternetExplorer ($ie=new
COM("InternetExplorer.Application") - see
http://php.net/manual/class.com.php) and work directly with the DOM.
That is, you can fill out the real live form, submit it, and the answer
comes back to the $ie COM object. This is a more powerful paradigm,
but not for the faint of heart.

The documentation says you shouldn't do this (when running php server
side. PHP CLI is fine) and that all sorts of mean, nasty, and ugly
things will happen if you do, but you can. However, there is a
limitation which I do consider significant when doing this server side:
the proper way to do this kind of thing (web page sequencing, that is)
is to use event driven programming (ie. you submit the page, it loads,
and when it's finished loading the appropriate php function gets called
- see http://php.net/com-event-sink).

The thing that happens is that your web server runs under security
restrictions. Specifically, COM objects are limited in what they can
do. In particular, COM objects are not allowed to interact with the
system at large, nor are they allowed to interact with other running
programs. These restrictions are understandable and reasonable since
your server is supposed to be running in a sandbox. However, PHP goes
too far and doesn't allow event sinking with IE in this instance. It
appears that this is a bug with PHP because if you use VBScript in the
same way at this point (indeed, if you have PHP call VBScript at this
point), then that VBScript's IE can be event driven, no problem, even
within the sandbox. The only recourse that I have found is to use
polling (ugh!).

Csaba Gabor from Vienna

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация