web_master Posted May 14, 2007 Share Posted May 14, 2007 Ive must to use frameset, but Ive made the site on 3 languages. How can I do it with cookies? the variable what will change the languages is: $lg thanks in advanced! Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/ Share on other sites More sharing options...
Psycho Posted May 14, 2007 Share Posted May 14, 2007 What is your issue specifically? A cookie is handled no differently with frames than with non-frames. You have provided no details on the structure of the pages (frames) or how you are wanting the user to choose their language. I would assume you would have a link for the use to change their language. I would further assume that the link would reload the parent frameset and the child frames with the proper languages. So, the functionality to set or read the cookie should be in the parent frameset code. Now you could make it complex by trying to reload all the current frames in the associated languages, but I would go with a process whereby if the user changes the language they go back tot he home page. Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-252745 Share on other sites More sharing options...
web_master Posted May 14, 2007 Author Share Posted May 14, 2007 OK, it must go back index file globally, because must change everything, not the one frame. exaple: ive got the admin panel where is a form ... <input type="text" name="scroll_en" value="<?php print $request['scroll_en'];?>"> <input type="text" name="scroll_sr" value="<?php print $request['scroll_sr'];?>"> <input type="text" name="scroll_hu" value="<?php print $request['scroll_hu'];?>"> ... that mean that Ive upload in dbase text on 3 language. That mean the user can read site on his own language. and that I mean an example for a query return: ( $lg is a variable for a language... ) (in dbase is scroll_on_sr, scroll_on_hu, scroll_on_en) $query_return = mysql_query("SELECT * FROM scroll WHERE scroll_on_".$lg."='1'"); ... if($lg == "sr") {$scroll_print = $request['scroll_sr']; } if($lg == "hu") {$scroll_print = $request['scroll_hu'];} if($lg == "en") {$scroll_print = $request['scroll_en'];} Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-252756 Share on other sites More sharing options...
Psycho Posted May 14, 2007 Share Posted May 14, 2007 Did you have a question there? I'm not sure what your response meant. Here is an example of how you could implement a language check: <?php $languageList = array ('sr','hu','en'); // Check to see if language choice was passed // on the query string; e.g. chosen with a link if ( isset($_GET[language]) && in_array ($_GET[language], $languageList) ) { $userLanguage = $_GET[language]; $_COOKIE[language] = userLanguage; // If choice was not selected see if user has a saved preference } else if ( isset($_COOKIE[language]) in_array ($_COOKIE[language], $languageList) ) { $userLanguage = $_COOKIE[language]; // user has not selected choice and no preference set - use a default } else { $userLanguage = 'sr'; $_COOKIE[language] = userLanguage; } ?> You could then reference $_COOKIE[language] on any page/frame to determine the language to display. Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-252818 Share on other sites More sharing options...
web_master Posted May 14, 2007 Author Share Posted May 14, 2007 dear mjdamato, I forgot to tell You that Im a beginner in PHP-programming... I need how can I send the cookie to browser, thant to read it. 1. can I do like this: index.php?lg=hu 2. to send cookie to browser 3. to read cookie on this example: $query_return = mysql_query("SELECT * FROM scroll WHERE scroll_on_".$lg."='1'"); ... if($lg == "sr") {$scroll_print = $request['scroll_sr'];} if($lg == "hu") {$scroll_print = $request['scroll_hu'];} if($lg == "en") {$scroll_print = $request['scroll_en'];} I hope for a help... Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-252890 Share on other sites More sharing options...
Psycho Posted May 14, 2007 Share Posted May 14, 2007 The code I provided above assumes that the user could set their language with a link with the selected language identified on the query string: href="index.php?language=en" However, I made a mistake in the above code. You cannot set a cookie using $_COOKIE[lnaguage] = "something". you have to use setcookie(). The following is the corrected code <?php $languageList = array ('sr','hu','en'); // Check to see if language choice was passed // on the query string; e.g. chosen with a link if ( isset($_GET[language]) && in_array ($_GET[language], $languageList) ) { $userLanguage = $_GET[language]; setcookie("language", $userLanguage, time()+3600*24*30); //Expires in 30 days // If choice was not selected see if user has a saved preference } else if ( isset($_COOKIE[language]) in_array ($_COOKIE[language], $languageList) ) { $userLanguage = $_COOKIE[language]; // user has not selected choice and no preference set - use a default } else { $userLanguage = 'sr'; setcookie("language", $userLanguage, time()+3600*24*30); //Expires in 30 days } ?> The code above also takes care of questions 2 & 3. The setting and reading of the cookie is taken care of. You should include this script (or a modified one) on the parent frame page and use $userLanguage within your queries. Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253040 Share on other sites More sharing options...
web_master Posted May 15, 2007 Author Share Posted May 15, 2007 <?php $languageList = array ('sr','hu','en'); // Check to see if language choice was passed // on the query string; e.g. chosen with a link if ( isset($_GET[language]) && in_array ($_GET[language], $languageList) ) { $userLanguage = $_GET[language]; setcookie("language", $userLanguage, time()+3600*24*30); //Expires in 30 days // If choice was not selected see if user has a saved preference } else if ( isset($_COOKIE[language]) in_array ($_COOKIE[language], $languageList) ) { $userLanguage = $_COOKIE[language]; // user has not selected choice and no preference set - use a default } else { $userLanguage = 'sr'; setcookie("language", $userLanguage, time()+3600*24*30); //Expires in 30 days } ?> why did I get this: Parse error: parse error in d:\internet\geneza\head_frame.php on line 12 (I made a temp.php file to try...) Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253292 Share on other sites More sharing options...
radar Posted May 15, 2007 Share Posted May 15, 2007 } else if ( isset($_COOKIE[language]) in_array ($_COOKIE[language], $languageList) ) { this is the part of your code you are having an issue with... now I tried playing with it a little bit, and it may or may not work I'm not sure.. you will have to test that as you are the one who knows what you want to happen.. but change the line above to } elseif (in_array ($_COOKIE[language], $languageList) ) { do that and you wont get the error, butif it works the way you want i cannot say.. but try it out and let me know. Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253295 Share on other sites More sharing options...
web_master Posted May 15, 2007 Author Share Posted May 15, 2007 its work in noframes, but in frames dont... if I do like: http://localhost/geneza/temp.php?language=en than change on: http://localhost/geneza/temp.php?language=hu it will change it (on second load), but in frameset dont work... Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253317 Share on other sites More sharing options...
radar Posted May 15, 2007 Share Posted May 15, 2007 Okay -- I did come up with another version of it, because you were calling to type of checks in one of the things so lets try changing line 12 to this instead... } else if ( isset($_COOKIE[language]) && in_array ($_COOKIE[language], $languageList) ) { isset and in_array are two different functions -- and so we need to set that.. so lets try that this time... Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253320 Share on other sites More sharing options...
Psycho Posted May 15, 2007 Share Posted May 15, 2007 I forgot the && clause in that line. I wrote that code from memory while I was at work. I was actually very close to the script I use personally: <?php //Create array of supported languages $languages = array('english', 'espanol'); //Check the $_GET value if exists if (isset($_GET['language']) && in_array($_GET['language'], $languages)) { $language = $_GET['language']; $_SESSION['language'] = $language; setcookie('language', $language, time()+60*60*24*365); //Check the COOKIE value if $language not set } elseif (isset($_COOKIE['language']) && in_array($_COOKIE['language'], $languages)) { $language = $_COOKIE['language']; $_SESSION['language'] = $language; //Check the SESSION value if $language not set (in case cookies disabled) } elseif (isset($_SESSION['language']) && in_array($_SESSION['language'], $languages)) { $language = $_SESSION['lang']; //Language still not set, use default } else { $language = $languages[0]; $_SESSION['language'] = $language; setcookie('language', $language, time()+60*60*24*365); } echo "<br>Current Language = " . $language . "<br><br>"; echo "<a href=\"".$_SERVER['PHP_SELF']."?language=english\">Choose English</a> "; echo "<a href=\"".$_SERVER['PHP_SELF']."?language=espanol\">Choose Espanol</a> "; ?> Just put this code into a file and include it at the top of the page of every script. You can then use the value of $language to determine what text to show. Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253322 Share on other sites More sharing options...
radar Posted May 15, 2007 Share Posted May 15, 2007 Man -- its old coding like this where you have to include that in every file that makes me glad i've switched over to using Smarty -- gosh it makes life friggen easy as a programmer lol.. But once i figured out the reason you had isset and in_array there i realized the && was missing on line 12 -- but that was too late to correct my previous post to the OP... Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253324 Share on other sites More sharing options...
web_master Posted May 15, 2007 Author Share Posted May 15, 2007 Man -- its old coding like this where you have to include that in every file that makes me glad i've switched over to using Smarty -- gosh it makes life friggen easy as a programmer lol.. But once i figured out the reason you had isset and in_array there i realized the && was missing on line 12 -- but that was too late to correct my previous post to the OP... I want to learn the Smarty to use... BYTHEWAY: radar, the code is work!!!!!!! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253333 Share on other sites More sharing options...
Psycho Posted May 15, 2007 Share Posted May 15, 2007 Smarty is nothing more than a template engine. If you are using templates you can simply include the file in your template(s). You don't need to include the language file on every page - you just need to include it for each page request. A page request may include many pages. You just need to find out the language once on each page call - prefereably before you need to get the text for that page. Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253337 Share on other sites More sharing options...
web_master Posted May 15, 2007 Author Share Posted May 15, 2007 Smarty is nothing more than a template engine. If you are using templates you can simply include the file in your template(s). You don't need to include the language file on every page - you just need to include it for each page request. A page request may include many pages. You just need to find out the language once on each page call - prefereably before you need to get the text for that page. Ive hear about it, and I downlad the smartyes scripts, but I dont know use it yet until Ive must to use the "old" version of programming... Ive use (and study) the PHP near 1 Year... you can see my works if You want, www.internetlabor.net Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253340 Share on other sites More sharing options...
radar Posted May 15, 2007 Share Posted May 15, 2007 I'm going to do something I've never done before, and only because it will not directly affect my site or the security of it... I am going to include both my index.php and my turbo.php which will show you the basics of using classes and Smarty for a large site... I also included the constructor.tpl file which is located in my templates folder that is required for smarty -- the part in the center that says {include file='../templates/default/admin/right.tpl'} also has this code in it.. {include file=$content} I did it this way mainly for the interface look... 'cause in the right.tpl there are more graphics... Hope it helps you even remotely to learn smarty -- though once i get my site done i can let ya know -- its a tutorial site for helping people with graphics and programming. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253341 Share on other sites More sharing options...
web_master Posted May 15, 2007 Author Share Posted May 15, 2007 Ive download it the files, but I must to see the installation of Smarty, and read some of Smarty before I use it - maybe Ive go to study some, and get a lesson from Smarty before I begin to use it... Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253352 Share on other sites More sharing options...
radar Posted May 15, 2007 Share Posted May 15, 2007 Installing smarty isn't really that hard -- just download the zip file, extract it and place them on your server (either local or otherwise) schmod your directories to 775 and you are done... all .tpl files go into the templates folder... it's really quite simple, and here are a few of my template files for you to look over as well.. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253353 Share on other sites More sharing options...
web_master Posted May 15, 2007 Author Share Posted May 15, 2007 Ive install - copy the Smarty in smarty dir in my local server but maybe I miss something, because Ive got the message after try to open youre files... (Ive made the changes in Youre files) php.exe has encountered a problem and needs to close. We are sorry for the inconvenience. Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253366 Share on other sites More sharing options...
radar Posted May 15, 2007 Share Posted May 15, 2007 That i've never seen... remember that your file locations will be different than mine... so in my turbo.php file you will want to change lines 71 thru 73 to the location of the folders on your end... in the index.php you will want to edit both line 13 and 14, 13 is the directory that smarty is located in -- and this means the Smarty.class.php file.. line 14 is the require for the turbo.php file... make sure these things are correct, and try it again... Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-253373 Share on other sites More sharing options...
web_master Posted May 19, 2007 Author Share Posted May 19, 2007 That i've never seen... remember that your file locations will be different than mine... so in my turbo.php file you will want to change lines 71 thru 73 to the location of the folders on your end... in the index.php you will want to edit both line 13 and 14, 13 is the directory that smarty is located in -- and this means the Smarty.class.php file.. line 14 is the require for the turbo.php file... make sure these things are correct, and try it again... Radar, it's OK, the Smarty works, Ive made a few simple examples... its great - my next (small) work will try to do with Smartys Quote Link to comment https://forums.phpfreaks.com/topic/51318-how-can-i-change-lang-if-i-use-frameset/#findComment-256833 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.