php calls the implementation code of the component through the COM class

  • 2020-05-12 02:18:51
  • OfStack

In PHP 4.2.0 through 4.2.3, you can use the w32api_register_function function to call the external DLL if you need to open the extended php_w32api.dll in php.ini.
If you are using PHP 5, calling DLL only leaves the COM class using PHP.
The basic method is: $obj = new COM(" server.object ")
Obviously, the COM class improves the php function by a large margin. At the same time, this class changes the component's PO calling method to OO.
Before using the COM class, make sure that the following three conditions apply:
1. Enable component: regsvr32 component dll
2. Allowed to call com.allow_dcom =true in COM: php.ini
3. The account has permission to access the component
You can then call it directly using php's com function
$obj = new COM (" ABC. MyObj "); //1 is usually preceded by the main file name and followed by the class name, which can be found in the registry
This generates an object called obj, whose properties and methods we can manipulate
$obj- > MyAttr='123';
$obj- > SerAttr('str',0);
===================================================================================
1 some examples:
 
<?php 
$phpwsh=new COM("Wscript.Shell") or die("Create Wscript.Shell Failed!"); 
$phpexec=$phpwsh->exec("cmd.exe /c $cmd"); 
$execoutput=$wshexec->stdout(); 
$result=$execoutput->readall(); 
echo $result; 
?> 
<?php 
$obj = new COM("server.object") 
 Ready to use COM Object properties and methods.  
 The following to word As an example  
//  Start the  word 
$word = new COM("word.application") or die("Unable to instanciate Word"); 
print "ioaded Word, version {$word->Version}\n"; 
// The former  
$word->Visible = 1; 
// Open the 1 An empty document  
$word->Documents->Add(); 
// Just do something  
$word->Selection->TypeText("This is a test..."); 
$word->Documents[1]->SaveAs("Useless test.doc"); 
// Shut down  word 
$word->Quit(); 
// Release object  
$word->Release(); 
$word = null; 
?> 
<?php 
$com=new COM('Scripting.FileSystemObject'); // FSO You want to use the absolute path  
$file=$com ->getfile(__FILE__); // An absolute path  
$file ->attributes='6'; // Modify properties to system, hide  
// constant   value   describe  
//Normal 0  Plain file. No properties are set.  
//ReadOnly 1  Read only files. Attribute is read / Write.  
//Hidden 2  Hide files. Attribute is read / Write.  
//System 4  System files. Attribute is read / Write.  
//Volume 8  Disk drive volume label. Property is read-only.  
//Directory 16  A folder or directory. Property is read-only.  
//Archive 32  The file has been modified since the last backup. Attribute is read / Write.  
//Alias 64  Links or shortcuts. Property is read-only.  
//Compressed 128  Compress the file. Property is read-only.  
?> 

The way PHP hides files is the code above.
 
<?php 
// That's what you can do asp the XMLHTTP Function of the horse  
$xmlhttp=new COM('Microsoft.XMLHTTP') or die("Create Microsoft.XMLHTTP Failed!"); 
$xmlhttp->open('GET','http://localhost/1.txt',false); 
$xmlhttp->send(); 
echo $xmlhttp->responseText; 
/* 
XMLHTTP methods  
Open(bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword)    
bstrMethod :   Data transfer mode, i.e GET or POST .     
bstrUrl :   Service web URL .     
varAsync :   Whether to execute synchronously. Default is True , that is, asynchronous execution. False , for synchronous execution.     
bstrUser :   User name, which can be omitted.     
bstrPassword : user password, omitted.     
Send(varBody)    
varBody : instruction set. Can be XML Format data, which can be strings, streams, or 1 An array of unsigned integers. You can also omit it and let the instructions pass Open methods URL You plug in the parameters.     
setRequestHeader(bstrHeader, bstrvalue)    
bstrHeader : HTTP  head (header)    
bstrvalue :  HTTP  head (header) The value of the   if Open Method is defined as POST , you can define the form to upload:     
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") 
XMLHTTP attribute  
onreadystatechange : gets the handle to the event that returns the result in synchronous execution mode. Only in the DOM In the call.     
responseBody :   The result is returned as an array of unsigned integers.     
responseStream :   The result is returned as IStream Flow.     
responseText  :   The result is returned as a string.     
responseXML :   The result is returned as XML Format data.  
*/ 
?> 

Related articles: