I am no good at php sessions, I have been doing a whole bunch of trial and error stuff and decided to come looking for help.
Here is my situation. I have my program able to read the default language file. The problem I am having now is how to get a visitor to change the language that he needs and also have the script hoster able to set his own default upon installation.
I currently have it working where the installer has the choice of choosing the default language from the database, but not sure how to get the script to read from the database and set the default.
Here is what I have so far:
get_language.php
[code]<?
if (empty($_SESSION[‘language’][‘lid’])) {
$_SESSION[‘language’][‘lid’] = ‘1’;
}
// mysql
include “inc/dbinfo.inc.php”;
$cnn = mysql_connect ("$dblocation", “$dbusername”, “$dbpassword”) or die ('I cannot connect to the database because: ’ . mysql_error());
if (!$cnn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("$dbname")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
$sql = "SELECT * FROM languages WHERE lid = " . $_SESSION[‘language’][‘lid’];
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo “No rows found, nothing to print so am exiting”;
exit;
}
while ($row = mysql_fetch_assoc($result)) {
$path = $row[‘lpath’];
}
mysql_free_result($result);
?> [/code]
index.php
[code]<?
include “./inc/get_language.php”;
include “./lang/”.$path."/install.lang.php"; ?>[/code]
What I can’t figure out is how to:
a] have the get_language.php file to read the variables(my table) $lang cell for the default lang. ie: $lang = ‘2’;
b] how to get the visitor to change the language on there own.
languages are as follow: lid = 1,2,3,etc…
lpath = english,french,spanish,etc…
Any input would be greatly appreciated.