I'm having an error here, how to load the specific folder as user selected in home.php?
My code:
<?php
$pass = array('home','main','result');
$lang = array('eng','thai');
if (in_array(@$_GET['page'], $pass, $lang)) {
include ($_SERVER['DOCUMENT_ROOT'] . './jeff/page/' . $_GET['$lang'] . '/' . $_GET['page'] . '.php');
}
elseif (!isset($_GET['page'])) {
include ($_SERVER['DOCUMENT_ROOT'] . './jeff/page/home.php');
} else {
include ($_SERVER['DOCUMENT_ROOT'] . './jeff/page/error.php');
}
?>
My home.php
<A href="Thai">Thai</a><br />
<a href="Eng">Eng</a>
inside my page folder, I have another two folder which is eng
and thai
.
I want the code to load eng or thai value to `$_GET['lang'] when user select the language from home.php
For example, if the user select Eng
the page will load main.php from eng folder and if the user select Thai
the page will load main.php from thai folder.
May I know where did I get wrong and the code is not working?
Thank you very much.
This may be a bit cleaner - don't think you need to further check for an error, since you know you can always default to home.php. Also, don't need the third in_array() param:
<?php
$baseUrl = $_SERVER['DOCUMENT_ROOT'] . './jeff/page/';
$pass = array('home','main','result');
$lang = array('eng','thai');
if(!isset($_GET['page']) && !isset($_GET['lang'])){
include ($baseUrl . 'home.php');
} else {
if (in_array($_GET['lang'], $lang)) {
$baseUrl .= $_GET['lang'];
}
if (in_array($_GET['page'], $pass)) {
$baseUrl .= $_GET['page'];
}
include ($baseUrl . '.php');
}