How can I get my include function to work?

96 views Asked by At

I'm making a website for out entertainment company. Because we work for a lot of foreigners, I tried to make the website multilangual. However, when I tested it all, the text came back as a blank. I think the problem lies within the common.php file, but I'm not sure. I used the common.php from a lad who made almost the same thing.

I have the whole site on one page (index.php) and the user goes with the js slider function to the next section. The translation script should work like this: the common.php file is included in my index.php. It checks what language is used by the user. Then the common.php SHOULD load the matching dictionary file in index.php. But it doesn't...

Any help on how to get my translated text loaded on the website would be really appreciated!

    <?php
/*
------------------
Taal: Nederlands
------------------
*/

$lang = array();

// Menu

$lang['MENU_FOTO'] = 'Fotogalerij';
$lang['MENU_INFO'] = 'Over ons';
$lang['MENU_AGENDA'] = 'Koncerten';
$lang['MENU_CONTACT'] = 'Contact';
?>

The header section in my index.php

<header>
    <div class="sticky-nav">
        <a id="mobile-nav" class="menu-nav" href="#menu-nav"></a>

        <div id="logo">
            <a id="goUp" href="#home-slider" title="Entertainment">Home</a>
        </div>

        <nav id="menu">
            <ul id="menu-nav">

                <li><a href="#foto"><?php echo $lang['MENU_FOTO']; ?></a></li>
                <li><a href="#work"><?php echo $lang['MENU_INFO']; ?></a></li>
                <li><a href="#about"><?php echo $lang['MENU_AGENDA']; ?></a></li>
                <li><a href="#contact"><?php echo $lang['MENU_CONTACT']; ?></a></li>
            </ul>
        </nav>

    </div>
</header>

And the common.php

<?php
session_start();
header('Cache-control: private'); 

if(isSet($_GET['lang']))
{
$lang = $_GET['lang'];

// register the session and set the cookie
$_SESSION['lang'] = $lang;

setcookie('lang', $lang, time() + (3600 * 24 * 30));
}
else if(isSet($_SESSION['lang']))
{
$lang = $_SESSION['lang'];
}
else if(isSet($_COOKIE['lang']))
{
$lang = $_COOKIE['lang'];
}
else
{
$lang = 'nl';
}

switch ($lang) {
  case 'nl':
  $lang_file = 'nederlands.php';
  break;

  case 'ba':
  $lang_file = 'bosnisch.php';
  break;

include_once .$lang_file;
?>

EDIT

I now even tried to include one of the language files directly into index.php. But now I'm really confused because that didn't work as well!

4

There are 4 answers

4
Limiter On
include_once($lang_file);

it's a function not a construct

0
Pupil On

Remove .

include_once $lang_file

1
doydoy44 On

Try to close the switch instruction.

switch ($lang) {
  case 'nl':
  $lang_file = 'nederlands.php';
  break;

  case 'ba':
  $lang_file = 'bosnisch.php';
  break;
} // close switch 

include_once $lang_file;
0
Dusa SFRJ On

I found it. The problem didn´t lie within de php coding. By some reason, my apache server´s settings got messed up and it did´t read any php, only html. So it actually showed the website as if you loaded it all from your computer, instead of from a server.

Anyways, thanks for the efforts!