A simple OLE automation using COM

NicAx64 0 Tallied Votes 720 Views Share

well PHP is a powerfull text processing language designed mainly as a CGI ( common Gateway Interface ) programming language. But PHP supports rest of other features using the library extensions.
For a example you can call any win32 API call in your PHP script using the win32 API library extension.

Like this you can use COM to create COM objects ,

Oky , the code shown bellow will open a internet explore window and
navigate to a particular web site.

<?php

// create an InternetExplorer object
$internetExplorer = new COM ( "InternetExplorer.Application") or die ("cannot create an Internet Explore Object object") ;
$internetExplorer->Visible = 1;
$internetExplorer->Navigate("http://www.bit.lk");


?>

Dani AI

Generated

showed the right idea — PHP can talk to COM on Windows — and 's pointer to PEAR OLE is one possible fallback. The failure reported by usually means PHP on that machine does not have the COM/COM+ extension available or the environment is not Windows/interactive, so the COM class cannot be instantiated.

Quick, practical checks you can run immediately (save and run from the same SAPI that serves your page — CLI vs Apache/IIS can differ):

<?php
echo 'OS: '.PHP_OS."\n";
var_dump(extension_loaded('com_dotnet'));

If that returns false, enable the extension in your php.ini (Windows builds) and restart your web server:

; php.ini (Windows)
extension=php_com_dotnet.dll

Important gotchas and tips:

  • COM support is Windows-only. If your host runs Linux, COM won't exist.
  • InternetExplorer.Application requires an interactive desktop session. It generally will not work or will behave unpredictably when invoked from services (IIS/Apache running as a service) or on headless servers. For server-side scraping/automation prefer cURL, a headless browser (Chrome/Chromium + Puppeteer) or Selenium WebDriver instead of automating IE.
  • Bitness matters: 32-bit PHP can only use COM objects registered for 32-bit; the same for 64-bit. Match PHP's bitness to the COM registration.
  • Security/concurrency: creating UI COM objects from a web request is unsafe and fragile; only use this pattern for local automation on trusted machines, not on public web servers.

Action checklist: confirm OS, check extension_loaded('com_dotnet'), enable php_com_dotnet.dll if needed, test from CLI as an interactive user, and switch to non-IE approaches for reliable server automation.

apradhan 0 Newbie Poster

Above code giving below error

Fatal error: Class 'COM' not found in /mnt/backup/home/apradhan/public_html/test/newbe.php on line 4

can you please let me know how I get this class.

psharma 0 Newbie Poster

For getting com conection error , you have to download the pear package of OLE.and install it in your web server

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.