I am able to connect to LDAP through unix but when I try to do the same through PHP am not able to. Below is the code,
$server ='server';
$port = 3060;
$ldapconn = ldap_connect($server, $port) or die("Could not connect " .
$server . ":" . $port . ".");
$user = "cn=orcladmin";
$password ='password';
$ldapbind = ldap_bind($ldapconn,$user,$password) ;
if(!$ldapbind)
{
echo ldap_error($ldapconn); #I get error invalid credentials
}
I am able to connect and also bind anonymously but in that case ldap_search does not work which is my final requirement. using the same credentials i.e cn=orcladmin and 'password' I am able to connect to ODSM.
Also Ihave tested the connection using below on unix,
ldapbind -h 'server' -p 3060 -D "cn=orcladmin" -w 'password'
it gives below message:
bind successful
Is user specified differently while connecting through PHP?
Could someone please help?
the issue was with ORACLE_HOME, not sure how to set it in PHP but I wrote a shell script where ORACLE_HOME was set and able to successfully run ldapbind and ldapsearch.
Related
I'm working with a service provider, who handles the hosting of the virtual server and the configuration of the LDAP server.
My job is to create a PHP application that use the LDAP to create a user at login (to keep things simple).
After many shares with the service provider, I finally achieve to contact the LDAP server with the following:
ldapsearch -x -LLL -h vmdc2.local -D email#local -w myPassword -b"CN=xxx,OU=APPLICATIF,OU=GROUPES,OU=UTILISATEUR,DC=enterprise,DC=local"
It comes from the ldap-utils Linux packet. This query returns good results.
So I created a simple script, trying to use the previous DN to list the users in CLI, for proof of work in PHP.
<?php
// create connection to LDAP server
$ldapconn = ldap_connect("ldap://vmdc2.local")
or die("Impossible to connect to the LDAP server.");
$ldapbind = ldap_bind($ldapconn, 'email#local', 'myPassword');
// check binding
if ($ldapbind) {
echo "Successfully connected to LDAP !" . PHP_EOL;
$dn = 'CN=xxx,OU=APPLICATIF,OU=GROUPES,OU=UTILISATEUR,DC=enterprise,DC=local';
$sr = ldap_list($ldapconn, $dn, 'cn=*');
if (false === $sr) {
die('Impossible to use the dn: ' . $dn . PHP_EOL);
}
$info = ldap_get_entries($ldapconn, $sr);
if ($info['count'] === 0) die('No entries :(');
for ($i=0; $i < $info["count"]; $i++) {
echo $info[$i]["cn"][0] . PHP_EOL;
}
} else {
$var = '';
ldap_get_option($ldapconn, LDAP_OPT_ERROR_STRING, $var);
echo "Connection to LDAP failed..." . PHP_EOL . $var . PHP_EOL;
}
The script output No entries :(
My questions
How can I get a different result from PHP on the same DN?
It is possible to configure how the LDAP server can answer, in the function of who is calling him?
It's my first time against LDAP, so I'm lost :/ Your help is really welcome!
HI Am trying to connect and unbind the server and port ldap connection using php.
Here is my code:
$hostname = 'ldaps://www.google.com';
$port = 636;
echo "ldap check";
$lp = ldap_connect($hostname,$port);
echo "servername";
echo $_SERVER['PHP_AUTH_USER'];
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
if ($bind = #ldap_bind($lp, $username.$hostname, $password)){
echo "Hello";
ldap_unbind($lp,$username,$password);
}
Failure:
But am not connecting with the ldap connection.PLease help me to fix the code.
When I read your code right, there are two issues:
The port you are giving will never be used in the ldap_connect. The docs clearly state that using the port as second argument to ldap_connect is deprecated and will only be used when you pass a servername or IP. But you are passing a URI, so that needs to include the port as well.
You are trying to bind as $username . $hostname. So you are tying to conntect 'someuser' as someuserldaps://www.google.com - I doubt that that will ever work. You probably want something like someuser#www.google.com...
I am trying to connect to (remote) AWS MYSQL database using php and ssl.
I created a database user and could connect with it from php and also on console.
Then I modified the user to use SSL with "require ssl" in the database.
I can stil connect on the console by:
mysql -h host -u username -p --ssl
But in php I get an ERROR 2002.
$con=mysqli_init();
mysqli_ssl_set($con,NULL,NULL,"cacert.pem",NULL,NULL);
$link = mysqli_real_connect($con, "host", "username", "password");
As far as I know the ssl_set parameters doesn't matter with AWS databases.
How to connect to Amazon RDS via SSL?
I think it has to do with the mysqli_ssl_set method, without it a connection is made and access is denied by database and this is the correct behaviour. It might be some configuration error on client side, but I have no idea what I shoud check.
The error is fired by mysqli_real_connect, as mysqli_ssl_set always returns true, just after it tries to connect will it receive an error.
I noticed it did not work for me until I specified the port. The following worked:
$db = mysqli_init();
$db->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
$db->ssl_set(NULL, NULL, 'rds-combined-ca-bundle.pem', NULL, NULL);
$db->connect($host, $user, $pass, $db, 3306);
$servername = "only-ssl-db.ct5b4uz1gops.eu-central-1.rds.amazonaws.com";
$username = "username";
$password = "password";
$dbname = "dbname";
$con = mysqli_init();
if (!$con){
die("mysqli_init failed");
}
mysqli_ssl_set($con,NULL,NULL,'rds-combined-ca-bundle.pem',NULL,'DHE-RSA-AES256-SHA');
if (!mysqli_real_connect($con,$servername, $username, $password, $dbname))
{
die("Connect Error: " . mysqli_connect_error());
}
// Some queries...
echo "Database connected";
printf("Client version: %d\n", mysqli_get_client_version());
mysqli_close($con);
I am attempting to connect to a mysql database using the c9.io development environment. I have followed their documentation and have seen multiple links, 1, 2 and 3.
I verified the mysql service is running. I also verified the PDO extension was installed via phpinfo(). Here is my current code:
$ip = getenv("REMOTE_ADDR");
$port = '3306';
$user = "username";
$db = "c9";
try{
$con = new PDO("mysql:host=$ip;port=$port;dbname=$db;charset=utf8",$user,"");
}
catch(Exception $e){
echo $e->getMessage();
}
I get the error Can't connect to MySQL server on '10.240.x.x' (111)
If i try localhost as host, I get the error Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I also followed a comment from the second link above: echo $IP in the terminal which returns 0.0.0.0
Any assistance appreciated.
You were on the right track. On https://docs.c9.io/setting_up_mysql.html it says use $IP for host. You can use getenv("IP") instead or use its value: 0.0.0.0. That should work.
Please try something like:
$dbname = 'c9';
$ip = getenv('IP');
$user = getenv('C9_USER');
mysql_connect($ip, $user, '') or die('Could not connect to mysql');
if (!empty($_POST)) {
$host = $_POST['host'];
$user = $_POST['user'];
$pass = $_POST['pass'];
$db = $_POST['db'];
echo '<pre>';
print_r($_POST);
$con = #mysqli_connect($host . ":3360", $user, $pass, $db);
// $con=#mysqli_connect('192.168.100.42','root','vertrigo','skates');
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else {
echo 'connected';
}
#mysqli_close($con);
}
I'm using this script to access remote db server in local(basically i want to access local db server through live webiste), howewer, I'm getting an error:
Failed to connect to MySQL: Unknown MySQL server host
'192.168.100.42:3360' (11004)
Please help to get out from this.
192.168.100.42 looks like a local IP. You'd need to try to connect to your static public IP and then forward port 3306 in your router to the 192.168.100.42 machine.
That's not your only problem;
Just because $_POST is not empty, don't assume it has those array keys set and not empty. Syntax like
if(isset($_POST['user'] && !empty($_POST['user'])))
Is much better.
Also, never use $_POST on any database interaction without sanitisation, and never connect to a database with the root user.
I don't know your exact application, but it's impossibly insecure.