我一直在寻找解决问题的方法,但结果过于复杂或过于简单。
我的网站有一个基本的登录框。我有一个我查询的LDAP服务器,用于输入用户名的信息,即positiontitle。
我有一个名为group_id的表,其中一列名为title。我想查询列以在DB中查找来自LDAP的用户位置标题的匹配项。因此,查询将需要包含一个变量。如果匹配,则会将用户定向到我网站上的某个页面。如果不匹配,请去其他地方。有什么建议吗?
这从LDAP
中提取信息 function getEmpInfo(){
<?php
$ldap = new WIN_LDAP('DEV');
$empNum = $_REQUEST['employeeNumber'];
$empResults = @$ldap->getEmpInfo($empNum);
$results = $empResults->positiontitle;
?>
}
这将在DB中查询匹配以指向正确的页面
$query = "Select title FROM group_id WHERE title = '$results' ";
$posResult = mysql_query($query);
if ($results === $posResult){
setcookie( md5("name"), md5($_REQUEST['enumber']), time()+3600, "/","", 0);
header('location: /admin.php');
} else {
setcookie( md5("general"), md5($_REQUEST['enumber']), false, "/","", 0);
header('Location: /general.php');
}
我知道上面的代码不起作用,但是,它会让你知道我正在尝试做什么
答案 0 :(得分:1)
发布编辑!
这应该有效:)
$myResult = mysql_query("SELECT title FROM group_id"); //This will select ALL titles
$matchFound = false;
while ($titles = mysql_fetch_row($myResult)) //This will fetch myResult until the
//last value. It's a sort of foreach.
{
if ($titles[0] == $results) //For each title grabbed, we check if it is equal to
//the $results variable. I wrote $titles[0] because mysql_fetch_row puts every row
//fetched in an array, where the indexes represent the columns. We selected only
//one column, so there is only $titles[0].
$matchFound = true;
}
if ($matchFound)
//Here goes the code to execute if you found the match
else
//You know it
请注意,必须在页面上显示任何布局之前发送标题,否则将不会发送标题。确保在php标记之前没有空格/返回,因为它会导致标题无法发送。
示例#1
//no space here
<?php
header (something); //this will be sent
?>
示例#2
//space
<?php
header(something); //this won't be sent
?>
示例#3
<html>
<?php
header(something); //this won't be sent neither
?>