What exactly does this PHP code do?

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-04-24T02:29:15Z Indexed on 2010/04/24 2:33 UTC
Read the original article Hit count: 249

Filed under:
|
|
|

Alright, my friend gave me this code for requesting headers and comparing them to what the header should be. It works perfectly, but I'm not sure why. Here is the code:

    $headers = apache_request_headers(); 
    $customheader = "Header: 7ddb6ffab28bb675215a7d6e31cfc759"; 
    foreach ($headers as $header => $value) { // 1
        $custom .= "$header: $value"; // 2
    }
    $mystring = $custom;  // 3
    $findme   = $customheader; // 4
    $pos = strpos($mystring, $findme); 
    if ($pos !== false) {
// Do something
} else{ exit(); } //If it doesn't match, exit.

I commented with some numbers relating to the following questions:

1: What exactly is happening here? Is it setting the $headers as $header AND $value?
2: Again, don't have any idea what is going on here. 
3: Why set the variable to a different variable? This is the only area where the variable is getting used, so is there a reason to set it to something else? 
4: Same question as 3.

I'm sorry if this is a terrible question, but its been bothering me, and I really want to know WHY it works. Well, I understand why it works, I guess I just want to know more specifically. Thanks for any insight you can provide.

© Stack Overflow or respective owner

Related posts about php

Related posts about strpos