Reading file and directory owner using PHP on the Windows - php

I have an intranet project based on the PHP and xampp server on the Windows. That intranet project have database with table where I store scanned disc drive informations of files and folders. I using simple windows command dir "$directory_path" /Q /T:C to get informations.
After that I use regex to match and parse that info to separate date, time, permission and dir name like on this example:
EXAMPLE REGEX FOR DIRECTORY PARSING
It's similar like this example: Get file owner in Windows using PHP
This working fine but sometimes file owner names are realy long and was stripped by command line. In that case I can't read full name and functionality is broken.
Now I searching for another solution.
My PHP have instaled also php_com_dotnet.dll extension and I using COM() class in some part of code.
My main question is:
-Can I use COM() class to get real file informations and avoid shell commands for the file search and listings and how?
-Is there some another extension, shell command or something 3rd what I can use to get file/folder owners?
NOTE: I need this only for the reading and indexing in the database, don't need to change permissions or ownership.

I find simple solution for this using PHP class COM() and the documentation of the IADsSecurityUtility::GetSecurityDescriptor method.
The code in PHP looks like this:
$path = 'D:\Some File\Some Another File\document.doc'; // File or dir path
$su = new COM("ADsSecurityUtility"); // Call interface
$securityInfo = $su->GetSecurityDescriptor($path, 1, 1); // Call method
echo $securityInfo->owner; // Get file owner
That's all folks.
NOTE
COM functions are only available for the Windows version of PHP.
.Net support requires PHP 5 and the .Net runtime.
As of PHP 5.3.15 / 5.4.5, this extension requires php_com_dotnet.dll
to be enabled inside of php.ini in order to use these functions.
Previous versions of PHP enabled these extensions by default.
You are responsible for installing support for the various COM objects

Related

using require() function to keep php source code safe

I have developed a local PHP application which runs on Apache. I want to distribute it to clients but don't want them or any IT guy they might have to be able to view the source code. I have looked into different encryption options and later found out that there is a website online where you copy the encrypted code and select the encryption software used and it'll decrypt the whole code. So I don't want to use any encryption.
This is a LOCAL application and has to run locally because it connects to a local database. Would it be possible to put all the php source files on an online server and create local php files with same name and only one line of code which includes the corresponding php file from online? For example, I put main 'showClients.php' online and create a local php file with same name, 'showClients.php', and put just one line of code in it like,
<?php
include('http://www.example.com/showClients.php');
?>
Is it practical in any sense?
You can't include that remote .php file because you got blank page mostly .
you can encrypt your code using various methods e.g ionCube or compile your php script to C++ .so extension using SWIG , php-cpp , , , compile a PHP extension (DLL file) in Windows , PHP-TO-C-Ext , zephir lang , PHC
to includes php files uses extension such as .inc so web server will display it as source code So you can grape it to your local machine .
to protect your showClients.php or the new showClients.inc you have to protect it from remot server to only allow your local machine to access that file .

search contents in php files in Windows 7

I have spent a long time looking for a way to search a phrase across some of my php files in Windows 7.
Things I have done include:
enabling “Always search file names and contents” in Windows Explorer;
adding php in the list of “Index properties and File Contents to enable content search” in Indexing Options;
making sure the directory is indexed;
making sure I have the permission to that directory (C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs).
What else should I try? Is that even possible to do that in Windows 7? If not, I’ll have to install Cygwin, which I am reluctant to do now.
Are you attempting to search the contents of each of the .php files themselves?
Or are you searching for a phrase in filenames with the corresponding .php file extension?
If your goal is the former, the following text editors can easily "Find all in open files" and even "Find all in folder(s)":
http://www.sublimetext.com/
http://notepad-plus-plus.org/
If what you're looking for is a command line option, the findstr command should serve you just fine. More information on findstr here.
If you're attempting to do the latter, then the link provided by Dany Caissy looks like it'll have just what you're looking for.
Linux/Unix has a grep command line utility for doing exactly what you want. If the built-in Win7 search/explorer capabilities don't do what you want, perhaps one of these links for third-party windows equivalents to grep:
Windows-equiv grep command line
Using Windows7 built-in findstr from command line
Note that Justice Cassel's answer has an excellent solution (search in all open files - +1 Justice), if you have your PHP files open in Notepad++. If you aren't using that NP++ for programming, you really should check it out. The FTP plugin (which automatically uploads a file every time you save it) is worth its weight, plus a dump truck, in gold.
In tools > folder options > search, you need to tick the box for always search file content.
Then when searching for a phrase e.g. "cats and dogs" you need to type the following in the search box
content:(~="cats and dogs").

Accessing PHP extensions within CakePHP

Our system uses a program called PDFlib TET for extracting data from PDF files. The software is installed as a PHP extension.
I have the software working fine outside of CakePHP, I can create a new TET object by calling:
$tet = new TET();
From any file - the extension I am including (php_tet.so) seems to simply work.
However, when I call this from within CakePHP I get the following error:
Class 'TET' not found.
Is there something basic I am missing here?
You have to include the extension in the php.ini file where you're executing the script. Mind that the command line version of PHP (CLI) uses a different php.ini than the webserver by default. E.g. on a recent Ubuntu Linux box, you have to make sure your
extension=php_tet.so
line is included both in /etc/php5/cli/php.ini and /etc/php5/apache2/php.ini.

How to call custom java methods from PHP?

I am new to both PHP and Java. Currently I am working on a project which call java class and its methods in the PHP code. I am creating a proof of concept for this. The problem is I am not able to connect custom class I have created in java. More over it could be said I don't know how to do it. I have used java.inc and javabridge.jar files to connect to the system classes but not able to connect to a simple class.
The step I have followed is:
Created a java package, class called clsForPHP and it has a method sum() which takes 2 parameters and returns integer value. (This is created using MyEclipse IDE)
Now I am trying to call this function from PHP. I have copied the jar file containg the package to PHP project. (Eclipse- Helios is the IDE)
$d= new java("clsForPHP.class");
Please help!! I have searched a lot but couldn't able to find a proper solution. What I think is this package should be added in the java.inc file but I don't know how to do it.
First of all install Tomcat6 and Java in you Unix box. Most probably your Tomcat will be on 8080 port. Now Download JavaBridge.war from http://php-java-bridge.sourceforge.net/pjb/ unzip it. Then from WEB-INF/lib folder copy JavaBridge.jar ,php-servlet.jar and php-script.jar in lib folder of Tomcat. Then copy JavaBridge.war in your Tomcat6 webapps folder and restart your tomcat6 service which will deploy automatically JavaBridge folder in your webapps
Now try to browse http://localhost:8080/JavaBridge/. If you get working than your PHP/Java Bridge installed. First Part is over.
Now make test page in your apache as below
<?php
require_once("http://localhost:8080/JavaBridge/java/Java.inc");
echo java("java.lang.System")->getProperties();
?>
and run it. If it works then you can start working with your work. If it not work then you have problem with you php.ini file. Try to make allow_url_once=on in your php.ini.
Now just copy your java jar file in tomcat /webapps/JavaBridge/WEB-INF/lib/ folder
and Just always put following line in your page where ever you want java to work
require_once("http://localhost:8080/JavaBridge/java/Java.inc");
$yourObj = Javav("your java class");
$yourObj->yourMethod();
$yourObj->setProperty("xxx");
Hope this can help you out.
IF you have still any problem get back.
Yea it will throw error because you must not have copied your java compiled file may be your jar file in PHP / Java Bridge.
You can to do in following 2 options way
If you have define your CATALINA_HOME then copy
$CATALINA_HOME/webapps/JavaBridge/WEB-INF/lib
If you have not define your CATALINA_HOME then copy
/var/lib/tomcat6/webapps/webapps/JavaBridge/WEB-INF/lib
Path which I am telling it assumes that you have install tomcat6, may be your tomcat webapps folder may be in different path.

PHP connectivity to Oracle DB

I am currently trying to write a PHP script to connect to an Oracle database. The reason I am using PHP is because I need to connect the Oracle database with my current CRM system, written in PHP/MySQL.
The PHP is hosted on 1&1 hosting, which is an external server. I read that I need to enable the extension php_oci8.dll to connect using oci_connect(), but I cannot do so since I do not have root privileges. Did a search, and couldn't find the DLL either.
Is there any other way around this? Any help greatly appreciated, please let me know if you need more information. Thanks!
1) 1&1 will have Linux, so you will have to use linux names for extensions. In this case name of extension will be php_oci8.so
2) create the php.ini in root directory and put the following line
extension=php_oci8.so
3) create a simple php script with one line to test if it works:
<?php phpinfo(); ?>
Please note -- 1&1 may physically not have that file available on their server (or some additional libraries that may be required by that extension). If the problem just with absence of .so file, then you can provide your own version of it (upload it and put the correct full path to the extension in php.ini)
Useful links: 1) http://faq.1and1.com/scripting_languages_supported/php/6.html 2) http://faq.1and1.com/scripting_languages_supported/php/8.html
According to your problem. first thing is that linux doesn't support .dll file.
You have to install OCI8 extension module in your Apache server.
Follow this link to get easy solution.
http://coffeewithcode.com/2012/09/how-to-install-oracle-libraries-for-php5-on-ubuntu-server/
Please check that there are no blank spaces.
1. put the php.ini and the php_oci8.so in the same folder as where you are going to run the php program that is going to access the database.
2. php.ini contents should look like:
extesion=./php_oci8.so

Categories