Jump to content

Echo certain content depending on who the visitor has logged in as


stickynote427

Recommended Posts

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?

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 :)

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.