Welcome to WebmasterWorld Guest from 3.227.233.55

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

switch not working

     
11:41 am on Nov 30, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:June 16, 2005
posts: 486
votes: 0


I pick up the correct username and when I echo it it prints as domain\johnsmith but it's still going to the die part of the switch statement.

ANy ideas why?

[code]

//$username = str_replace("DOMAIN\\\\", "", $_SERVER['REMOTE_USER']);
$username = $_SERVER['LOGON_USER'];

//make user name lowercase
$username = strtolower($username);

switch ($username)
//make sure all strings in the switch statement are lower case
{
case "domain\joebloggs";
InsertAudit($username);
break;

case "domain\johnsmith";
InsertAudit($username);
break;

default:
InsertAudit($username);
die("You are logged on as ".$username.". <br />
You do not have permission to view this page. <br />
}

12:09 pm on Nov 30, 2007 (gmt 0)

Full Member

10+ Year Member

joined:July 22, 2005
posts:202
votes: 0


have you checked to make sure there are no trailing spaces?

"domain\johnsmith " and "domain\johnsmith" will echo out the same on the screen, but the first will fail the case.

12:11 pm on Nov 30, 2007 (gmt 0)

Senior Member from FR 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
posts: 4449
votes: 11


case... is not " ; "
BUT case...:
:)
12:54 pm on Nov 30, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:June 16, 2005
posts: 486
votes: 0


There are no leading spaces but I suppose I should check for them in the code anyway.
I changed all the case; to case: but still doesn't work.
My logon works fine and mine is at the top but none of the others.
1:08 pm on Nov 30, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:June 16, 2005
posts: 486
votes: 0


would the backslash cause a problem?
5:39 pm on Nov 30, 2007 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2003
posts:3416
votes: 0


nm, I didn't see that you already fixed that. :/

Added: I would use single quotes instead of double-quotes. Your "\" might be interpreted as escaping the letter following it...

Also, the die statement is missing a trailing double quote and closing parentheses. (I imagine that is just a copy error though.)

10:51 am on Dec 7, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:June 16, 2005
posts: 486
votes: 0


still not working:


<?php

include_once("db.php");

//$username = str_replace("DOMAIN\\\\", "", $_SERVER['REMOTE_USER']);
$username = $_SERVER['LOGON_USER'];

//make user name lowercase
$username = strtolower($username);

function InsertAudit($username)
{
if (empty($_SERVER['HTTP_REFERER'])) {$referrer = "";} else {$referrer = $_SERVER['HTTP_REFERER'];}
if (empty($_SERVER['REQUEST_URI'])) {$uri = "";} else {$uri = $_SERVER['REQUEST_URI'];}
if (empty($_SERVER['HTTP_USER_AGENT'])) {$agent = "";} else {$agent = $_SERVER['HTTP_USER_AGENT'];}

$query = "insert into LoginAudit
(page, referrer, browser, ip, loginname)
values
('".$uri."', '".$referrer."', '".$agent."', '".$_SERVER['REMOTE_ADDR']."', '".$username."')";

mssql_query($query) or die(mssql_get_last_message());
}

//debug
$creditControlUser = 0;
$superUser = 0;
$FinanceUser = 1;
$readOnlyUser = 1;

switch ($username)
//make sure all strings in the switch statement are lower case
{
case 'adcsl\jbloggs':
InsertAudit($username);
//$superUser = 1;
break;

case 'adcsl\abloggs':
InsertAudit($username);
//$superUser = 1;
break;

case 'adcsl\bbloggs':
InsertAudit($username);
//$creditControlUser = 1;
break;

case 'adcsl\cbloggs':
InsertAudit($username);
//$creditControlUser = 1;
break;

default:
InsertAudit($username);
die("You are logged on as ".$username.". <br />
You do not have permission to view this page. <br />
");

}

?>

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members