Hi, I have a problem. I have a webpage in which I need to change language, so I came up with a .XML file with various language like malay, chinese and english.
So in my index.php, I have
<?php
session_start();
include 'linkings.php';
include 'parseXML.php';
?>
So the parseXML.php is the instructions for the XML dictionary to work.
I could link the index and the parseXML.php and my database, but the problem is that how could I display the values in my webpage?
e.g. <?php echo $lang->login; ?> but the login doesn't display...
What object does the $lang variable contain in the first place? Please don't just show us a few lines of code and expect us to know how does your code works. The least you can do is to upload a sufficient amount of your code to a file host and paste the download URL here.
This is a file:
---------------------------------------
<?php
//---------------------------
// Parse XML
//---------------------------
if (isset($_COOKIE['cookieLanguage'])) {
if (file_exists("lang.xml")) {
$xml = simplexml_load_file("lang.xml");
}
else {
die("Language file not found");
}
if ($_COOKIE['cookieLanguage'] == "language") {
$lang = $xml->English;
}
else if ($_COOKIE['cookieLanguage'] == "Malay") {
$lang = $xml->Malay;
}
else if ($_COOKIE['cookieLanguage'] == "Swedish") {
$lang = $xml->Swedish;
}
}
else {
if (file_exists("lang.xml")) {
$xml = simplexml_load_file("lang.xml");
$lang = $xml->English;
}
else {
die("Language file not found");
/* Cannot be Language File Not found because RP have secured the FTP vulnerabilities*/
}
}
?>
-----------------------------
2nd File:
<?php
function showloginForm(){
echo "<table >
<form name='loginform' id='loginform' action='login.php' method='post'>
<tr >
<td align='left'>";
echo $lang-> language -> username;
echo ":</td>
<td ><input type='text' name='log' id='log' value='' size='15'tabindex='1' /></td>
</tr>
<tr >
<td>"; $lang->password; echo "</td>
<td><input type='password' name='pwd' id='pwd' value='' size='15' tabindex='2' /></td>
</tr>
<tr>
<td align='center' colspan='2'><a href='register.php'>Register</a>|<a href''>Forgot Login</a> | <input type='submit' name='submit' id='submit' value='Login' tabindex='4' /></font></td>
</tr>
</table>";
}
?>
------------------------------------
3rd file
<?xml version="1.0" encoding="iso-8859-1"?>
<languages>
<language>
<type>English</type>
<title>Login Form</title>
<username>Username</username>
<password>Password</password>
<forgot>Forgot your password? Click here</forgot>
</language>
</language>
-----------------------------------
The problem is, why I cannot echo out the username and password?
anyway, the lang.xml is just a small part of it.
Don't know if it will work but you can try to modify your XML file to below:
<?xml version="1.0" encoding="iso-8859-1"?>
<languages>
<english>
<title>Login
Form</title>
<username>Username</username>
<password>Password</password>
<forgot>Forgot your
password? Click here</forgot>
</english>
<malay>
<title>Malay Login
Form</title>
<username>Malay Username</username>
<password>Malay Password</password>
<forgot>Malay Forgot your
password? Click here</forgot>
</malay>
</languages>
Then change this part
if ($_COOKIE['cookieLanguage'] == "language")
{
$lang =
$xml->English;
}
else if ($_COOKIE['cookieLanguage'] == "Malay")
{
$lang = $xml->Malay;
}
else if ($_COOKIE['cookieLanguage'] ==
"Swedish") {
$lang =
$xml->Swedish;
}
to
if ($_COOKIE['cookieLanguage'] == "language")
{
$lang =
$xml->english;
}
else {
$lang =
eval("\$xml->" . strtolower($_COOKIE['cookieLanguage']) . ";");
}
Change
echo $lang-> language -> username;
to
echo $lang->username;
Ok, I have tried to modify the codes but it still cannot work... anyway;
------------------------------------------------------------------------------------------
1st file; ParseXML.php (This file displayed errors ; Parse error: parse error, unexpected T_ELSE in C:\Program Files\xampp\htdocs\plaincart\parseXML.php on line 22)
<?php
//---------------------------
// Parse XML
//---------------------------
if (isset($_COOKIE['cookieLanguage'])) {
if (file_exists("lang.xml")) {
$xml = simplexml_load_file("lang.xml");
}
else {
die("Language file not found");
}
if ($_COOKIE['cookieLanguage'] == "language") {
$lang = $xml->english;
}
else {
$lang = eval("\$xml->" . strtolower($_COOKIE['cookieLanguage']) . ";");
}
else if ($_COOKIE['cookieLanguage'] == "malay") {
$lang = $xml->malay;
}
else if ($_COOKIE['cookieLanguage'] == "swedish") {
$lang = $xml->swedish;
}
}
else {
if (file_exists("lang.xml")) {
$xml = simplexml_load_file("lang.xml");
$lang = $xml->english;
}
else {
die("Language file not found");
}
}
?>
------------------------------------------------
2nd file: linkings;
function showloginForm(){
echo "<table >
<form name='loginform' id='loginform' action='login.php' method='post'>
<tr >
<td align='left'>";
echo $lang->username;
echo ":</td>
<td ><input type='text' name='log' id='log' value='' size='15'tabindex='1' /></td>
</tr>
<tr >
<td>"; $lang->password; echo "</td>
<td><input type='password' name='pwd' id='pwd' value='' size='15' tabindex='2' /></td>
</tr>
<tr>
<td align='center' colspan='2'><a href='register.php'>Register</a>|<a href''>Forgot Login</a> | <input type='submit' name='submit' id='submit' value='Login' tabindex='4' /></font></td>
</tr>
</table>";
}
---------------------------------------------
3rd file;
<?xml version="1.0" encoding="iso-8859-1"?>
<languages>
<english>
<type>English</type>
<title>Login Form</title>
<username>Username</username>
<password>Password</password>
......................
so that will be it, any help??
if (isset($_COOKIE['cookieLanguage'])) {
if (file_exists("lang.xml")) {
$xml =
simplexml_load_file("lang.xml");
}
else {
die("Language file not
found");
}
if ($_COOKIE['cookieLanguage'] == "language")
{
$lang =
$xml->english;
}
else {
$lang =
eval("\$xml->" . strtolower($_COOKIE['cookieLanguage']) .
";");
}
else if ($_COOKIE['cookieLanguage'] == "malay")
{
$lang = $xml->malay;
}
else if ($_COOKIE['cookieLanguage'] ==
"swedish") {
$lang =
$xml->swedish;
}
}
else {
if (file_exists("lang.xml")) {
$xml =
simplexml_load_file("lang.xml");
$lang =
$xml->english;
}
else {
die("Language file not
found");
}
}
Remove the part that is in red. The eval code will handle all your language cases.
function showloginForm(){
echo "<table >
<form name='loginform' id='loginform'
action='login.php' method='post'>
<tr >
<td
align='left'>";
echo
$lang->username;
echo ":</td>
<td ><input
type='text' name='log' id='log' value='' size='15'tabindex='1'
/></td>
</tr>
<tr >
<td>"; echo $lang->password; echo "</td>
<td><input
type='password' name='pwd' id='pwd' value='' size='15' tabindex='2'
/></td>
</tr>
<tr>
<td align='center'
colspan='2'><a
href='register.php'>Register</a>|<a href''>Forgot
Login</a> | <input type='submit' name='submit' id='submit'
value='Login' tabindex='4' /></font></td>
</tr>
</table>";
}
Added the part in red.