Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,208,037 members, 8,001,200 topics. Date: Wednesday, 13 November 2024 at 06:20 AM

How Can I Connect Php Script To Active Directory With XAMPP Server - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How Can I Connect Php Script To Active Directory With XAMPP Server (2028 Views)

How To Increase Localhost Xampp Server Memory Limit ! / HELP - Installing A PHP Script On My Website Using GITHUB / Installing Joomla With Xampp (local Host Sever) (2) (3) (4)

(1) (Reply) (Go Down)

How Can I Connect Php Script To Active Directory With XAMPP Server by hundu: 3:27pm On Mar 12, 2015
Please any help...
i always get this error anytime i try.
Fatal error: Call to undefined function ldap_connect() in C:\xampp\htdocs\Active_directory\index.php on line 9


<?php

if(isset($_POST['username']) && isset($_POST['password'])){

$adServer = "ldap://trustfundpensions.net";

$ldap = ldap_connect($adServer);
$username = $_POST['username'];
$password = $_POST['password'];

$ldaprdn = 'mydomain' . "\\" . $username;

ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);

$bind = @ldap_bind($ldap, $ldaprdn, $password);


if ($bind) {
$filter="(sAMAccountName=$username)";
$result = ldap_search($ldap,"dc=MYDOMAIN,dc=COM",$filter);
ldap_sort($ldap,$result,"sn"wink;
$info = ldap_get_entries($ldap, $result);
for ($i=0; $i<$info["count"]; $i++)
{
if($info['count'] > 1)
break;
echo "<p>You are accessing <strong> ". $info[$i]["sn"][0] .", " . $info[$i]["givenname"][0] ."</strong><br /> (" . $info[$i]["samaccountname"][0] ."wink</p>\n";
echo '<pre>';
var_dump($info);
echo '</pre>';
$userDn = $info[$i]["distinguishedname"][0];
}
@ldap_close($ldap);
} else {
$msg = "Invalid email address / password";
echo $msg;
}

}else{
?>
<form action="#" method="POST">
<label for="username">Username: </label><input id="username" type="text" name="username" />
<label for="password">Password: </label><input id="password" type="password" name="password" /> <input type="submit" name="submit" value="Submit" />
</form>
<?php } ?>
Re: How Can I Connect Php Script To Active Directory With XAMPP Server by FRInteractives: 6:33pm On Mar 12, 2015
Did you include or require the file where you declared the ldap_connect(). Function?

You must include that file to this page using the require_once() So that php can find that file.
Re: How Can I Connect Php Script To Active Directory With XAMPP Server by hundu: 8:37am On Mar 13, 2015
I'm connecting from the same page. Below is my connection.
Thanks.
$adServer = "ldap://trustfundpensions.net";

$ldap = ldap_connect($adServer);
$username = $_POST['username'];
$password = $_POST['password'];
Re: How Can I Connect Php Script To Active Directory With XAMPP Server by FRInteractives: 9:29am On Mar 13, 2015
So does the idap_connect() function exists? You have to create the function first before you use it if it doesn't exists, if the function exists in
a remote file also include that file in to every page you will use the function

hundu:
I'm connecting from the same page. Below is my connection.
Thanks.
$adServer = "ldap://trustfundpensions.net";

$ldap = ldap_connect($adServer);
$username = $_POST['username'];
$password = $_POST['password'];
Re: How Can I Connect Php Script To Active Directory With XAMPP Server by hundu: 12:58pm On Mar 17, 2015
How can i create the ldap_connect() function. Sample code please.
Re: How Can I Connect Php Script To Active Directory With XAMPP Server by FRInteractives: 4:29pm On Mar 17, 2015
This is the php syntax to create any function:

<?php

function idap_connect() {
//function codes goes here

}

?>
hundu:
How can i create the ldap_connect() function. Sample code please.

1 Like

Re: How Can I Connect Php Script To Active Directory With XAMPP Server by hundu: 10:19am On Mar 19, 2015
@ FRInteractives. Thanks
Re: How Can I Connect Php Script To Active Directory With XAMPP Server by FRInteractives: 11:55am On Mar 19, 2015
You're Welcome
hundu:
@ FRInteractives. Thanks

(1) (Reply)

Learn How To Build Websites With Java EE / How Was O2tvseries.com Built / Cracking The Credit Card Algorithm

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 18
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.