Reputation: 111
I've searched to find a resolution to problem, but the results were too complex, or too simple.
I have a basic login box to my site. I have an LDAP server that I query, to pull in the username's information, i.e. positiontitle.
I have a table named group_id, with a column named title. I want to query the column to find a match of the user's positiontitle from LDAP, in the DB. So, the query will need to include a variable. If there is a match, the user will be directed to a certain page on my site. If no match, go somewhere else. Any suggestions?
This pulls in the info from LDAP
function getEmpInfo(){
<?php
$ldap = new WIN_LDAP('DEV');
$empNum = $_REQUEST['employeeNumber'];
$empResults = @$ldap->getEmpInfo($empNum);
$results = $empResults->positiontitle;
?>
}
This will query the DB for a match to direct to the correct page
$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');
}
I know the code above does not work, but, it will give you an idea of what I'm trying to do
Upvotes: 3
Views: 149
Reputation: 513
Post Edited!
This should work :)
$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
Please note that headers must be sent BEFORE displaying any layout on the page, otherwise they will not be sent. Ensure there are no spaces/returns before your php tag because it will cause the headers to not be sent.
Example #1
//no space here
<?php
header (something); //this will be sent
?>
Example #2
//space
<?php
header(something); //this won't be sent
?>
Example #3
<html>
<?php
header(something); //this won't be sent neither
?>
Upvotes: 1