首先,我仍然是PHP的新手
我有这个: valid.php
<?php
session_start();
// -------------- CHANGE VARIABLES TO SUIT YOUR ENVIRONMENT --------------
//LDAP server address
$server = "domain.com";
//domain user to connect to LDAP
$user = ($_POST['username']);;
//user password
$psw = ($_POST['password']);
// storing session username
$_SESSION['username'] = $user;
//FQDN path where search will be performed. OU - organizational unit / DC - domain component
$dn = "OU=Domain,DC=Domain,DC=com";
// ------------------------------------------------------------------------
// connecting to LDAP server
$ds=ldap_connect($server) or die ("Could not connect to LDAP server.");
$r=ldap_bind($ds, $user , $psw);
if($r){
ldap_close($ds);
}else{
echo '<div id="container" class="container_24" alpha align="center">';
echo '<h1>La data no coincide <br /> RE-INGRESA Usuario y Clave</h1>';
echo '</div>';
} //if $r
?>
我的目标是做一个ldap_bind来验证用户是否存在于Microsoft Exchange目录中(我已经这样做了),然后在$ _SESSION ['username']中存储$ user的值,以便在我的wordpress页面中使用它向用户问好:
这是header.php:
的一行if(isset($_SESSION['username'])){
echo '<div class="container" class="container_24" alpha align="center">';
echo '<div class="flow-text">Hola, '.$_SESSION['username'].'</div>';
echo '</div>';
}else{
echo '<div class="container" class="container_24" alpha align="center">';
echo '<div class="flow-text">No has iniciado sesión</div>';
echo '</div>';
}
问题是它只运行一次,不知道为什么,对此的解释会很好,我试图将valid.php的代码放在functions.php中但是同样的事情发生了,我有什么选择?