Hi,
I'm trying to create a multilingual site and I've decided to go with the example shown here. The problem is that I'm also trying to build the site with a method I've never used before. The navigation is done through the get-method. All content gets loaded into the index file, depending on what is in the url different content gets loaded (e.g. ?page=home or ?page=contact). But in the index I include my file called navigation which looks like this (I've stripped the code so that it only contains what's necessary):

<?php
//Depending on the $navigation variable the site loads different content into the page
if ($navigation == 'home'){
	home();
}
else {
	firstPage();
}

//Here below is each function for each possible navigation option
#home
function home(){
	include "php/header/mm-header.php";
	
	include "php/home/mm-home.php";
}

function firstPage(){
	include "php/first_page/mm-first_page.php";
}
?>

This is included in the index file.

so the page mm-home.php is included-included if you understand what I mean, it is included in a file that gets included. This is because I think it's much easier working with smaller files

I forgot to mention that when you first come to the site you get the option to view it in either english or an alternative language and after that you are redirected to the home-page.

The problem I face is that I need the language variable that is created in the index file, not through inclusion, to work in mm-home.php. The way I do it looks like this:

//Fetching the information needed to navigate the site
$navigation = mysql_real_escape_string($_GET['page']);


if (isset($_GET['lang'])){ 
	$_SESSION['lang'] = mysql_real_escape_string($_GET['lang']);
}
else { 
   $_SESSION['lang'] = 'en';
}

//Getting the correct language
$directory = 'languages';
include_once($directory.'/'.$_SESSION['lang'].'.lng');

I've been trying different ways to get the variable $language, which I've in a last desperate attempt tried to use in a session, to work in the included-included file mm-home.php. Because it seems like the server processes the code in mm-home.php before it gets included or something. Or maybe it's processed when I include it the first time because the variable doesn't work in the content loaded from mm-home.php. It works if I load the language once again in mm-home.php but it seems like unnecessary much code, it must be a simpler way to do it.

Earlier I've tried to do this working purely with $_GET but it didn't work so that is why I've chosen to try sessions. Does anyone have any idea how I should do this?

Ok, now I've tried having all the content from the navigation.php file directly in index so that mm-home.php only gets included once. Now it still just writes everything out without the effects that the php-code should have given. Please help?

Ok, now I'm just confused. I tried putting

echo $txt['global_footer_website-design'];

in front of the function and behind it as well as changing the language within the mm-home.php that gets included. In front and behind of it it is the language first chosen in the top of the index-page. The language change within the included file only made a difference to the content within and not what comes afterwards in the code of the index-file. And that is just plain weird. Because the file is included and the variable is global so why doesn't it change the rest of the file?!


echo $txt;

Now I see that this behaviour occurs only when the content, included or not, is within a function that is called. So I've decided to skip the functions entirely and only use an if-else statement. Thanks... for all the feedback... x)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.