Php Test

Hello . This file contains a few HTTP related php tricks. You can look at the pretty printed source code !

Date

Hello, it's 16:45, Friday April 19 2024. Still 54 days to go until my birthday.

Request Headers:

Will display the request headers (sent by the client):

headers[accept] = */*
headers[user-agent] = Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
headers[referer] = http://tecfa.unige.ch/guides/php/examples/http-basics/test.php
headers[host] = tecfa.unige.ch

Will display all environment variables in $argv (probably none here):


Standard CGI variables:

.... a long scary list about yourself and ourselves

\n"; } ?>

Will display get, post, cookie variables (probably none here)
($HTTP_GET_VARS[], $HTTP_POST_VARS[] and $HTTP_COOKIE_VARS[] arrays):
\n"; } echo "

"; } 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]."
\n"; } echo "

"; } 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]."
\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.
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.

"); /* 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; } ?> Selected language ==>: "); ?> Result ==> :


D.K.S.