It is possible to use the header() function to send an “Authentication Required” message to the client browser causing it to pop up a Username/Password input window. Once the user has filled in a username and a password, the URL containing the PHP script will be called again with the predefined variables PHP_AUTH_USER, PHP_AUTH_PW, and AUTH_TYPE set to the user name, password and authentication type respectively. These predefined variables are found in the $_SERVER array. Both “Basic” and “Digest” (since PHP 5.1.0) authentication methods are supported Continue reading HTTP Authentication
Tag Archives: HTTP
setrawcookie()
It sends an HTTP cookie without URL encoding the cookie value
Example
<?php
setrawcookie(“time”,time());
echo $_COOKIE[‘time’];
?>
Output
1337938950
setcookie()
It sends an HTTP cookie to a client
Example
<?php
setcookie(“time”,time());
echo $_COOKIE[‘time’];
?>
Output
1337938449
headers_sent()
It checks whether headers have been sent .
Example
<?php
if (!headers_sent()) {
header(“Location: http://www.phpcodez.com/”);
exit;
}
?>
headers_list()
It returns a list of response headers sent
Example
<?php setcookie("time",time()); header('Content-type: text/plain'); echo "<pre>"; print_r(headers_list()); ?>
Output
<pre>Array ( [0] => X-Powered-By: PHP/5.3.3-1ubuntu9.10 [1] => Set-Cookie: time=1337938449 [2] => Content-type: text/plain )
header()
It sends a raw HTTP header to a client.
Example
<?php
header(‘Location: http://www.phpcodez.com/’);
?>
HTTP functions
- header() – It sends a raw HTTP header to a client.
- headers_list() – It returns a list of response headers sent
- headers_sent() – It checks whether headers have been sent .
- setcookie() – It sends an HTTP cookie to a client
- setrawcookie() – It sends an HTTP cookie without URL encoding the cookie value