NorthWestSimulations Posted July 24, 2008 Share Posted July 24, 2008 Okay, I got a problem. First Ill start off by sharing my source code then ill explain my problem: <?php if(!is_dir('src/require')){ echo('<b>Fatal Error '.__LINE__.''); die('<br />Suspended Operation \"Requires\"</b>'); } if(file_exists('src/require/globals.php')){ require_once('src/require/globals.php');}else{die('Could Not Load Enviroment'); } if(file_exists('src/require/action.php')){ require_once('src/require/action.php');}else{die('Could Not Load Action Globals'); } if(file_exists('src/require/functi.php')){ require_once('src/require/functi.php');}else{die('Could Not Load Action Globals'); } if($_COOKIE['language'] == NULL){ setcookie("language", "en", time()+$langcookie, "/", "24.76.180.135", 0);} // 99 Years if($_COOKIE['language'] == NULL){ echo '<script type="text/javascript"> window.location = "/index.php" </script>';} // Refresh if(!is_dir('src/lang')){ echo('<b>Fatal Error '.__LINE__.''); die('<br />Suspended Operation \"Language\"</b>'); } if(file_exists('src/lang/'.$_COOKIE['language'].'.php')){ require_once('src/lang/'.$_COOKIE['language'].'.php');}else{die("Please Reload This Page.<br /><b>To Avoid Getting This Error Make Sure Cookies And Javascript is Enabled On Your Browser<b>"); } $page = substr(mysql_real_escape_string(htmlspecialchars($_GET['page'])), 0, 32); $action = mysql_real_escape_string(htmlspecialchars($_GET['action'])); ?> well heres my problem. I have this script to switch languages and depending on what language you chose it loads a file that is full of nothing but arrays. like: <?php // Overall Website $lang['website_name'] = "Untitled Site "; $lang['copyright'] = "VAHost système programmé par Adlai Kowitch | Toutes les heures sont en Format ZULU (2400Z)"; $lang['username'] = "Nom d'utilisateur"; $lang['password'] = "Mot De Passe"; $lang['login'] = "Connectez-vous"; // Homepage $lang['construction_head'] = "Site en construction"; $lang['construction_body'] = "Nous sommes actuellement en cours de construction à l'heure actuelle.<br />Mais nous allons essayer d'obtenir en ligne sous peu. S’il vous plaît rester avec nous"; $lang['english'] = "English"; ?> and this is the script for changing languages: <?php $action = $_GET['action']; if ($action == "lang.fr"){ setcookie("language"); setcookie("language", "fr"); echo '<script type="text/javascript"> window.location = "/index.php" </script>'; } elseif ($action == "lang.en"){ setcookie("language"); setcookie("language", "en"); echo '<script type="text/javascript"> window.location = "/index.php" </script>'; } ?> So everything works fine but this script does require refreshing using javascript to perform properly. I have tried for about 3 hours to change it so that when a Cookie is registered it also registers a session because you cannot register a cookie and take information from it in one page load (Hence the refreshing) but using sessions you can. ya see? Also if the user disables cookies then the page doesnt stop refreshing and it crashes the browser while if the user disables javascript then they get an error. So is anyone following me? I need a way for users to switch languages while registering a cookie and a session at the same time containing the same data and a way for the languages to load without the page having to rely on javascript for refresh. Thanks in advance EDIT: I appologize for the messy scripting. I code by using the least amount of lines as possible so if someone steals my script off the FTP it will be hard to read. Link to comment https://forums.phpfreaks.com/topic/116470-solved-multiple-languages/ Share on other sites More sharing options...
NorthWestSimulations Posted July 24, 2008 Author Share Posted July 24, 2008 Sorry I was confusing you people. I just decided to start over and re-code it, this is what I got: <?php if(!is_dir('src/require')){ echo('<b>Fatal Error '.__LINE__.''); die('<br />Suspended Operation \"Requires\"</b>'); } if(file_exists('src/require/globals.php')){ require_once('src/require/globals.php');}else{die('Could Not Load Enviroment'); } if(file_exists('src/require/action.php')){ require_once('src/require/action.php');}else{die('Could Not Load Action Globals'); } if(file_exists('src/require/functi.php')){ require_once('src/require/functi.php');}else{die('Could Not Load Action Globals'); } if(!isset($_COOKIE['language'])){setcookie("language", "en", time()+$langcookie, "/", "24.76.180.135", 0); $language = "en";} if(!isset($_COOKIE['language'])){require_once('src/lang/'.$language.'.php');} else { require_once('src/lang/'.$_COOKIE['language'].'.php'); } ?> And as confusing as that is it did work! so...... ...TOPIC SOLVED!!! Link to comment https://forums.phpfreaks.com/topic/116470-solved-multiple-languages/#findComment-598951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.