headers[Host] = tecfa.unige.ch
headers[Accept-Encoding] = gzip, br, zstd, deflate
headers[User-Agent] = Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
headers[Accept] = */*
Will display all environment variables in $argv (probably none here):
//echo $GLOBALS["DOCUMENT_ROOT"];
for(reset($GLOBALS); $key = key($GLOBALS); next($GLOBALS)) {
echo "GLOBALS[$key] = ".$GLOBALS[$key]."
Will display get, post, cookie variables (probably none here) ";
}
if ($HTTP_POST_VARS) {
for(reset($HTTP_POST_VARS); $key = key($HTTP_POST_VARS); next($HTTP_POST_VARS)) {
echo "\$HTTP_POST_VARS[$key] = ".$HTTP_POST_VARS[$key]." ";
}
if ($HTTP_COOKIE_VARS) {
for(reset($HTTP_COOKIE_VARS); $key = key($HTTP_COOKIE_VARS); next($HTTP_COOKIE_VARS)) {
echo "\$HTTP_COOKIE_VARS[$key] = ".$HTTP_COOKIE_VARS[$key]." ");
/* Try to figure out which language to use.
*/
function negotiate_language() {
global $supported_languages, $HTTP_ACCEPT_LANGUAGE, $default_language;
/* If the client has sent an Accept-Language: header,
* see if it is for a language we support.
*/
if ($HTTP_ACCEPT_LANGUAGE) {
$accepted = explode(",", $HTTP_ACCEPT_LANGUAGE);
for ($i = 0; $i < count($accepted); $i++) {
if ($supported_languages[$accepted[$i]]) {
return $accepted[$i];
}
}
}
return $default_language;
}
?>
$chosen_language = (negotiate_language()); ?>
Selected language ==>: echo($chosen_language . " "); ?>
Result ==> :
switch ($chosen_language) {
case "fr":
print "Ah bonjour !";
break;
case "en":
print "Oh hello !";
break;
}
?>
for ($i=0; $iStandard CGI variables:
.... a long scary list about yourself and ourselves
\n";
}
?>
($HTTP_GET_VARS[], $HTTP_POST_VARS[] and $HTTP_COOKIE_VARS[] arrays):
// echo "$HTTP_GET_VARS";
if ($HTTP_GET_VARS) {
for(reset($HTTP_GET_VARS); $key = key($HTTP_GET_VARS); next($HTTP_GET_VARS)) {
echo "\$HTTP_GET_VARS[$key] = ".$HTTP_GET_VARS[$key]."
\n";
}
echo "
\n";
}
echo "
\n";
}
}
?>
Check language and customize output
This example shows how to select a language based on the clients preference
and what you decide to offer. Modified example from
PX:PHP Code Exchange.
echo ("Client/Browser accepted languages = $HTTP_ACCEPT_LANGUAGE. ");
$supported_languages = array(
"en" => 1, /* English */
"fr" => 1 /* French */
);
$default_language = "en";
/* echo for testing, ought to have a loop here */
echo ("Languages we support in this script = en, fr. Default language = $default_language.
D.K.S.