0

I need to access a specific custom header to determine what content to serve. I can get the headers and output an array like this:

<?php
    headers = apache_request_headers();
    foreach ($headers as $header => $value) {
        echo "$header: $value <br />\n";
     }
?>

It outputs all headers, the one I need to access is: X-Language-Locale: it-IT

I need to parse all of the array for "X-Language-Locale" and run an if else statement to determine what content to serve. How do I do this?

2

2 Answers 2

1

You can access it without the foreach loop.

if($headers['X-Language-Locale'] == 'it-IT') {
    echo 'ok';
}else {
    echo 'not italian';
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can probably use indexed access, since you have a constant key that you want to look for. Most objects that have key-value pairs can also be accessed using the key as an index.

<?php
    $headers = apache_request_headers();
    $lang_locale = $headers["X-language-locale"];
    if ($lang_locale == "it-IT") {
        // DO SOMETHING
    } else {
        // DO SOMETHING ELSE
    }
?>

1 Comment

Normal situation this would work perfectly. Due to the translation proxy we're using the content gets a little mangled. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.