stickynote427 Posted April 22, 2009 Share Posted April 22, 2009 I'm trying to work on a navigation bar PHP file that is included in each of my Web pages. I'm trying to echo different content depending on who the visitor has logged in as. I am using .htaccess and .htpasswd for authentication, so here is the code I'm using: <?php if ($_SERVER['PHP_AUTH_USER']=="visitor") { echo "Hello, Visitor."; } ?> But nothing is echoed. Even if I try to confirm that the user is logged in as "visitor" by using echo $_SERVER['PHP_AUTH_USER'] nothing is echoed. How should I do this? Link to comment https://forums.phpfreaks.com/topic/155177-echo-certain-content-depending-on-who-the-visitor-has-logged-in-as/ Share on other sites More sharing options...
tang Posted April 22, 2009 Share Posted April 22, 2009 Your code looks correct. Are you logged in as visitor? Link to comment https://forums.phpfreaks.com/topic/155177-echo-certain-content-depending-on-who-the-visitor-has-logged-in-as/#findComment-816342 Share on other sites More sharing options...
taith Posted April 22, 2009 Share Posted April 22, 2009 But nothing is echoed. Even if I try to confirm that the user is logged in as "visitor" by using echo $_SERVER['PHP_AUTH_USER'] nothing is echoed. thats saying that your not logged in as visitor... hence it wont say that you are logged in as visitor, since you arnt Link to comment https://forums.phpfreaks.com/topic/155177-echo-certain-content-depending-on-who-the-visitor-has-logged-in-as/#findComment-816346 Share on other sites More sharing options...
stickynote427 Posted April 22, 2009 Author Share Posted April 22, 2009 Your code looks correct. Are you logged in as visitor? As far as I know..."visitor:(password)" is in my .htpasswd file, and that's what I type in to log in ("visitor") to my site as a visitor. Link to comment https://forums.phpfreaks.com/topic/155177-echo-certain-content-depending-on-who-the-visitor-has-logged-in-as/#findComment-816525 Share on other sites More sharing options...
taith Posted April 22, 2009 Share Posted April 22, 2009 print_r($_SERVER); that'll show you for sure wether your variable is being set(typo maybe then?)... or not... Link to comment https://forums.phpfreaks.com/topic/155177-echo-certain-content-depending-on-who-the-visitor-has-logged-in-as/#findComment-816532 Share on other sites More sharing options...
stickynote427 Posted April 23, 2009 Author Share Posted April 23, 2009 Alright, I used print_r($_SERVER), and found a variable that I think works ($_SERVER['SCRIPT_FILENAME']). Here is what I finally have: <?php $ifVisitor=stripos($_SERVER['SCRIPT_FILENAME'],$_SERVER['DOCUMENT_ROOT']."/visitor"); $ifAdmin=stripos($_SERVER['SCRIPT_FILENAME'],$_SERVER['DOCUMENT_ROOT']."/auth"); if ($ifVisitor>-1) { echo "<a href=\"(my site URL)/visitor/index.php\">Visitor Home</a>"; } if ($ifAdmin>-1) { echo "<a href=\"(my site URL)/auth/index.php\">Admin Home</a>"; } ?> Is this the best way to do this? Link to comment https://forums.phpfreaks.com/topic/155177-echo-certain-content-depending-on-who-the-visitor-has-logged-in-as/#findComment-817029 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.