Remove $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW']

Hello, when I get to logout page, I'd like to remove $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW']

How can I get it?
portal123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CWS (haripriya)Commented:
unset($_SERVER['PHP_AUTH_USER']);
unset($_SERVER['PHP_AUTH_PW']);
0
hernst42Commented:
unset does not work in this case. You have to send headers to reauth the user, so the remote browser know the credentials are no longer valid , but tat will be very confusing for the enduser

function authenticate() {
    header('WWW-Authenticate: Basic realm="Test Authentication System"');
    header('HTTP/1.0 401 Unauthorized');
    echo "You must enter a valid login ID and password to access this resource\n";
    exit;
}

Why do you want to unauth the user in that case?
0
nplibCommented:
why not use $_SESSION variables to authenticate, you can't unset $_SERVER variables.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

portal123Author Commented:
Hello, guys.

unset does not work.

To hernst42, Reason what i unauth is when a user can access to admin pages  again he can get in there without id,password.

To nplib, this is for mobile site and some mobile browers do not accept session variables. $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_USER']  are OK on them.

Thanks,portal
0
nplibCommented:
because you can't unset a $_SERVER variable. They exist as part of the server.

why not set these variables to be empty, then test for this emptyness for your login/logout purposes.


$_SERVER['PHP_AUTH_USER'] = "";

if (empty($_SERVER['PHP_AUTH_USER'])) {
   do stuff
} else {
  do other stuff
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
portal123Author Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.