Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

carlosbutler

macrumors 6502a
Original poster
Feb 24, 2008
691
2
I am trying to do some PHP and one thing im trying is to do a site with multiple languages.

One small part is this below (i just reduced it so that is sort of works, but with the error part in it):

<?php session_start() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">
/*--------- Links ---------*/
a {
color:#FFF;
text-decoration:none
}
/*--------- Top navigation bar ---------*/
.nav-bar-top {
height:50px;
}
.nav-bar-top-left {
background-image:url(images/nav-top-bar-left.png);
font-family:Verdana, Geneva, sans-serif;
color:#FFF;
text-align:center;
}
.nav-bar-top-left:hover {
background-image:url(images/nav-top-bar-left-rollover.png);
}
.nav-bar-top-bg {
background-image:url(images/nav-top-bar-bg.png);
font-family:Verdana, Geneva, sans-serif;
color:#FFF;
text-align:center;
}
.nav-bar-top-bg:hover {
background-image:url(images/nav-top-bar-bg-rollover.png);
}
.nav-bar-top-right {
background-image:url(images/nav-top-bar-right.png);
font-family:Verdana, Geneva, sans-serif;
color:#FFF;
text-align:center;
}
.nav-bar-top-right:hover {
background-image:url(images/nav-top-bar-right-rollover.png);
}
/*--------- Content ---------*/

</style>

<!-- Favicon Icons -->
<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="images/favicon.ico">
</head>

<body>
<?

// Making sure that a page is selected
if(isset($_GET['page'])) {
$page = $_GET['page'];
}
else {
$page = 'abc';
}
?>
<?
switch($page) {
case 'destinations':
if ($lan=='gb'){
echo'<table width="980" border="0" cellpadding="0" cellspacing="0" class="nav-bar-top">';
echo'<tr>';
echo'<td width="163" class="nav-bar-top-left">Destinations</a></td>';
echo'<td width="163" class="nav-bar-top-bg">Flights</td>';
echo'<td width="163" class="nav-bar-top-bg">Hotels</td>';
echo'<td width="164" class="nav-bar-top-bg">Extras</td>';
echo'<td width="164" class="nav-bar-top-bg">My Bookking</td>';
echo'<td width="163" class="nav-bar-top-right">Contact and FAQs</td>';
echo'</tr>';
echo'</table>';}
else {
echo'<table width="980" border="0" cellpadding="0" cellspacing="0" class="nav-bar-top">';
echo'<tr>';
echo'<td width="163" class="nav-bar-top-left">Destinos</a></td>';
echo'<td width="163" class="nav-bar-top-bg">Vuelos</td>';
echo'<td width="163" class="nav-bar-top-bg">Hoteles</td>';
echo'<td width="164" class="nav-bar-top-bg">Extras</td>';
echo'<td width="164" class="nav-bar-top-bg">Mi Reserva</td>';
echo'<td width="163" class="nav-bar-top-right">Contacto y FAQs</td>';
echo'</tr>';
echo'</table>';}
break;
case 'abc':
echo 'OMG';
break;
default:
echo 'default';
break;
}
?>
<table width="980" border="0" cellpadding="0" cellspacing="0" class="nav-bar-top">
<tr>
<td width="163" class="nav-bar-top-left"><a href="anywhere" >Destinations</a></td>
<td width="163" class="nav-bar-top-bg">Flights</td>
<td width="163" class="nav-bar-top-bg">Hotels</td>
<td width="164" class="nav-bar-top-bg">Extras</td>
<td width="164" class="nav-bar-top-bg">My Booking</td>
<td width="163" class="nav-bar-top-right">Contact and FAQ's</td>
</tr>
</table>
</body>
</html>

in the switch section, i am trying to get it so that the page changes with the variable $lan, but i can seem to make it work. the switch cases work fine, but i can seem to get the language part to work. if you notice there is english in the if.... and spanish for the else.... it always goes to spanish. i have tried by also declaring the variable and doing $lan=='gb' and $lan=='es' and that way it will work. but when typing in the address bar www....file.php?page=destinations&lan=uk
(or es) it doesnt seem to change

any help thanks!
carlos
 
unless the server has register globals enabled (which it shouldn't) -- you need to define $lan. ie,

if ($_GET['lan']) $lan = $_GET['lan']; else $lan = 'gb';
 
so does this need to be done for anything of this type. as you may have guessed, i have literally just started off PHP today:p
 
You'll also want to make sure $page is defined outside the if..else statements to ensure that it has the proper scope for the switch statement.

PHP:
// Making sure that a page is selected
$page = 'abc';
if (isset($_GET['page'])) {
  $page = $_GET['page'];
}

And as kungfu was trying to say, you need to define what $lan is. Currently it's never set equal to anything so your if statement is comparing against null/undefined.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.