server-variables

HTTP Auth via PHP - PHP_AUTH_USER not set?

a 夏天 提交于 2019-11-26 21:03:18
问题 I tried to implement a small authentication via http and copied this bit of code from the net to check whether this will work properly: <?php if(!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="My Realm"'); header('HTTP/1.0 401 Unauthorized'); echo 'Text to send if user hits Cancel button'; exit; } else { echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>"; echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>"; } ?> However, my browser always ask for a

What is the difference between HTTP_HOST and SERVER_NAME in PHP?

廉价感情. 提交于 2019-11-25 23:12:43
问题 When would you consider using one over the other and why? 回答1: The HTTP_HOST is obtained from the HTTP request header and this is what the client actually used as "target host" of the request. The SERVER_NAME is defined in server config. Which one to use depends on what you need it for. You should now however realize that the one is a client-controlled value which may thus not be reliable for use in business logic and the other is a server-controlled value which is more reliable. You however