I have a php script modified from cgi-interactive that uses the COM InternetExplorer.Application to open up a browser log on to a form and submit it. It works great if its ran from the command line but I need it to be ran from a browser, any suggestions?
When I run this script from a browser it doest do anything. I also tried using the exec to try and run it from cmd from browser still nothing.
Code:
//class
class MechanizeIE {
var $ie = NULL;
function StartIE() {
$this->ie = new COM("InternetExplorer.Application")
or die("Unable to start IE");
/* set the co-ordiantes
for the IE window */
$this->ie->left = 400;
$this->ie->top = 0;
$this->ie->width = 600;
$this->ie->height = 400;
/* turn off all toolbars */
$this->ie->menubar = 1;
$this->ie->toolbar = 1;
$this->ie->statusbar = 1;
/* make IE visible */
$this->ie->visible = 1;
}
function navigateIE ($url) {
$this->ie->navigate($url);
$this->wait_while_busy();
}
function setformIE ($textbox, $value) {
$index = 0;
$cnt = 0;
$doc = $this->ie->Document;
$forms = $doc->forms;
for($i = 0; $i < $forms->length; $i++) {
$form = $forms->item($i);
for($j = 0; $j < $form->elements->all->length; $j++)
{
$e_name = $form->elements->all{$j}
->getAttribute("name");
if($e_name == $textbox) {
if($index == $cnt) {
$form->elements->all{$j}->{value} = $value;
return;
} else {$cnt++;}
}
}
}
print "could not find form element : " . $textbox . "\n";
}
function pushbuttonIE ($button) {
$index = 0;
$cnt = 0;
$doc = $this->ie->Document;
$forms = $doc->forms;
for($i = 0; $i < $forms->length; $i++) {
$form = $forms->item($i);
for($j = 0; $j < $form->elements->all->length; $j++) {
$e_name = $form->elements->all{$j}
->getAttribute("value");
$e_type = $form->elements->all{$j}
->getAttribute("type");
if($e_name == $button and $e_type == submit) {
if($index == $cnt) {
$form->elements->all{$j}->click();
$this->wait_while_busy();
return;
} else {$cnt++;}
}
}
}
print "could not find form button : " . $button . "\n";
}
}
//main script
include 'classMechanizeIE.php';
$myIE = &New MechanizeIE;
$myIE->StartIE();
$myIE->navigateIE('mysite.com');
$myIE->setformIE('username', 'user');
$myIE->setformIE('password', 'pass');
$myIE->pushbuttonIE('Login');
When I run this script from a browser it doest do anything. I also tried using the exec to try and run it from cmd from browser still nothing.