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 21:16, Monday October 23 2017. Still 232 days to go until my birthday.

Request Headers:

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

headers[Host] = tecfa.unige.ch
headers[Accept-Encoding] = x-gzip, gzip, deflate
headers[User-Agent] = CCBot/2.0 (http://commoncrawl.org/faq/)
headers[Accept] = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

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.