PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am creating a help system. I call help.php?id=15 and in help.php a language file with the text for page 15 is included. If there is no file it should display the 'no help available text'.
Well on my multi-lingual website, I have a form select on every page to change the language. And I include this file at the top of every page, it determines the language two letter code to use. And after it, I use include with the language code to include the right language file. Might give you some ideas. If you want to talk more about internationalization of websites with me, you can priv msg me ok.
<?php
// Very Uppermost Code for Every php Page
// Only PHP Code Allowed Here!
$tlcode = $_COOKIE['browselang'];
// Did they execute the change lang dropdown?
if ($_POST['selectlang']) {
setcookie("browselang", $_POST['selectlang'], (time() + (3600 * 24 * 365 * 10)), "/");
$tlcode = $_POST['selectlang'];
}
// Get the two letter code from the browser prefered language
$prefer_tlc = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
// Get the main language file and apex (charset codes)
// If the cookie isn't there, try HTTP_ACCEPT_LANGUAGE
// if we support it, else default to english.
if (empty($tlcode)) {
if (file_exists("language/".$prefer_tlc)) {
// If /cms/language/<tlc_here>/ exists, set it to that.
setcookie("browselang", $prefer_tlc, (time() + (3600 * 24 * 365 * 10)), "/");
include("language/".$prefer_tlc."/apex-".$prefer_tlc.".".$phpEx);
include("language/".$prefer_tlc."/cpsnav-".$prefer_tlc.".".$phpEx);
$tlcode = $prefer_tlc;
} else {
// Set it to English (Default)
setcookie("browselang", "en", (time() + (3600 * 24 * 365 * 10)), "/");
include("language/en/apex-en." . $phpEx);
include("language/en/cpsnav-en." . $phpEx);
$tlcode = "en";
}
} else {
include("language/".$tlcode."/apex-".$tlcode."." . $phpEx);
include("language/".$tlcode."/cpsnav-".$tlcode."." . $phpEx);
}
// Turn off Warnings
error_reporting(E_ERROR | E_PARSE);
// We have to send this header at the top of every php page
// This defines the language used on the page
header('Content-Type: text/html; charset=' . $charset);
?>
Sounds like you're making the same mistake I always make....
Not pointing to the full path for the include file... (I have a nasty habit of just giving the file name and pulling my hair out every time. Now I go shoot myself in the foot...)