asdas
asdas

Reputation: 113

Can someone explain me what the header function actually does?

Can someone explain me what the header function actually does? I looked in the PHP manual but that was not clear to me so I actually didn't understand. Here is the function which I should digest.

function ofunc_startusr ($GETID="_usrid_",$FORCE=false)
{
$a = explode(".",$_SERVER["SERVER_NAME"]);
$dom =".".$a[(count($a)-2)].".".$a[(count($a)-1)];

if($GETID!==false && isset($_GET[$GETID]) && $_GET[$GETID])
{
    session_set_cookie_params(0,"/",$dom); 
    session_id($_GET[$GETID]);
    session_name("_usr_"); 
    session_start();
 header("Location: ".($_SERVER["REDIRECT_URL"]?                                  

     $_SERVER["REDIRECT_URL"]:"/")); 

    exit;
} 
elseif($FORCE || (isset($_COOKIE["_usr_"]) && $_COOKIE["_usr_"]))
{
    session_set_cookie_params(0,"/",$dom);
    session_name("_usr_"); 
    session_start();

    return true;
}
return false;

}

Upvotes: 0

Views: 87

Answers (1)

Quentin
Quentin

Reputation: 943240

When using HTTP, the client will make a request and the server will make a response. There are two parts to each of these - the headers and the (optional) body.

For example, when you submit a form, the browser will make a POST request. The headers will include things like the URL the form is being submitted to, and the body will include the data from the form.

When the server makes a response, it will first send the headers and then the body. The headers will include information such as what sort of data the body contains (such as "This is an HTML document" or "This is a PNG image"), what time the resource was last modified (for caching purposes), new cookies to set, and so on. The body will then contain the HTML document / image / etc.

The PHP header function lets you specify the headers you want to send back.

Upvotes: 2

Related Questions