-1

I'm developing a code which uses ldap_search Shell Script Command for extracting user information from Active Directory using user id and by proper LDAP Server Authentication. I am getting accurate result from ldap_search script.

But, whenever I put the shell script inside exec or shell_exec PHP command, I'm not getting anything.

All the other shell scripts are working fine with the help of PHP exec command except ldap_search.

Is there some additional task left for me to do?

Is ldap_search and exec/shell_exec not compatible with each other?

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • My bad, I can see now that your attempting to run a **PHP script** using shell? Can you show us exactly what your are trying to do (preferably with minimum code) along with any errors which are being shown. – Kitson88 Jan 19 '17 at 07:44
  • Update-1: My sample code is like this: >result.txt; ?> – pritam saha Jan 19 '17 at 09:28

1 Answers1

0

You must use echo exec('your command or script');

Make sure to have permissions to run it. I mean, the web user must have permissions to execute that.

May seem obvious, but I think your failure is in something basic like this. You must put echo to show the result of the command.

EDIT After reading your new comments about it and using that new info... I saw you are trying to redirect the output to a file... but maybe you have 2 different problems.

  1. Have the user which is executing php (usually www-data) permission to write on the folder where the php is?

  2. Your code has quotes inside quotes that must be escaped using . Try this:

<?php exec("ldapsearch -x -v -h 'LDAP://server' -p '389' -D 'uid=\"domain_user_id\",ou=users,ou=internal,o=\"organization\"' -w 'domain_password' -b 'ou=users,ou=internal,o=organization' 'uid=person's_user_id' >> result.txt"); ?>

So you don't need echo if you want the output in a file. And the redirection >> can be inside the command executed, not in php.

Remember that > replaces de file and what you have >> add at the end of the file.

OscarAkaElvis
  • 5,384
  • 4
  • 27
  • 51
  • My sample code is like this: >result.txt; ?> – pritam saha Jan 19 '17 at 09:29
  • As you can see I have used echo to print my output. As I have said in my problem nothing is wrong with php command "exec()". I have already tried it with simple shell script commands such as "pwd", "ifconfig" etc. Just ldapsearch is not working. As for permission, in centOS terminal ldapsearch output by bash execution is coming perfectly. – pritam saha Jan 19 '17 at 09:34