Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php mechanize

Status
Not open for further replies.

tswitz00

IS-IT--Management
Jan 26, 2005
67
US
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?


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.
 
Web applications do their work on the server, not the client. So the only way I can see to invoke a client-side COM object would be for a web-script to sent to a client enough VBscript or maybe Java code to get the job done.

However, I must warn you that security setting will give you a fight trying to do what you're doing. If you can automagically fetch a log file through my browser, what's to stop you from fetching any other file on my system?


Want the best answers? Ask the best questions! TANSTAAFL!
 
if it must be run from a browser, save the page as an hta file and have your client download it the execute locally. it will run in IE with wide permissions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top