karlc Posted February 10, 2006 Share Posted February 10, 2006 Hi AllI am looking around for some good tutorials on setting up a multilingual website using MySql and PHP in DW. Having just moved over to PHP from ASP I was also wondering if I could adapt this ASP VB tutorial to suit my needs.[a href=\"http://www.webthang.co.uk/tuts/tuts_dmx/rob11/rob11_1.asp\" target=\"_blank\"]http://www.webthang.co.uk/tuts/tuts_dmx/rob11/rob11_1.asp[/a]Any help would be much appreciated Quote Link to comment Share on other sites More sharing options...
degsy Posted February 10, 2006 Share Posted February 10, 2006 You shouldn't have many problems converting that tutorial. The only real difference is the variable syntax. e.g.ASP = session("var")PHP = $_SESSION['var']; Quote Link to comment Share on other sites More sharing options...
karlc Posted February 11, 2006 Author Share Posted February 11, 2006 Thanks for the adviceThis tip got rid of my errorAlthough I still cant change the language I have a feeling its got to do with this partThe ASP<%'Set up language selectionIf Request.QueryString("lang")="Spanish" ThenSession("Language")="Spanish"ElseIf Request.QueryString("lang")="French" ThenSession("Language")="French"ElseIf Request.QueryString("lang")="English" ThenSession("Language")="English"End If%>I tried the following PHP but no joy :( anyone know what I am doing wrong?<%If $_SERVER["QUERY_STRING"]("lang")="Spanish" Then$_SESSION["Language"]="Spanish"Else $_SERVER["QUERY_STRING"]("lang")="French" Then$_SESSION["Language"]="French"Else $_SERVER["QUERY_STRING"]("lang")="English" Then$_SESSION["Language"]="English"End If%> Quote Link to comment Share on other sites More sharing options...
AndyB Posted February 11, 2006 Share Posted February 11, 2006 It's not 100% clear what your code is trying to achieve, but I'll assume that somewhere in the URL is something like ?lang=french. Retrieving a URL-passed parameter needs only that you look at the $_GET array. Quick code that ought to be close:[code]<?php$lang = $_GET['lang'];if ($lang) { if ($_SESSION['Language']!=$lang) { $_SESSION['Language'] = $lang; }}[/code] Quote Link to comment Share on other sites More sharing options...
karlc Posted February 11, 2006 Author Share Posted February 11, 2006 Hi AndyBYou have solved my problem the languages are changing...thank you :)However I have one small error On loading the page I get this errorUndefined index: lang online 3and when I click to change a language and it changes it ok I get this errorUndefined variable: _SESSION on line 41.<?php2.$lang = $_GET['lang'];3.if ($lang) {4. if ($_SESSION['Language']!=$lang) { 5. $_SESSION['Language'] = $lang;6. }7.}Any further help would be great Quote Link to comment Share on other sites More sharing options...
AndyB Posted February 11, 2006 Share Posted February 11, 2006 OK, glad that got you going. The code was a "quick'n'dirty" effort :)You're not actually seeing errors, you're seeing warning notices. Good to have while testing, but can always be turned off (later) by reducing the error_reporting level. If I have a minute this afternoon I'll amend that so it runs notice-free for you - or maybe some friendly soul will beat me to it. Quote Link to comment Share on other sites More sharing options...
karlc Posted February 12, 2006 Author Share Posted February 12, 2006 If you find the time that would be great I only moved over to PHP yesterday and it looks like I have a big learning curve that’s for sureYour kick-start is much appreciated Thanks again Quote Link to comment Share on other sites More sharing options...
AndyB Posted February 12, 2006 Share Posted February 12, 2006 This produces no errors and no warnings (for me).[code]<?phpsession_start(); error_reporting(E_ALL);// can be removed laterif (isset($_GET['lang'])) { $lang = $_GET['lang']; $_SESSION['Language'] = $lang;} else { if (isset($_SESSION['Language'])) { $lang = $_SESSION['Language']; }}if (!isset($lang)) { $lang = "english"; // the default language}echo "We speak ". $lang. " here";?>[/code] Quote Link to comment Share on other sites More sharing options...
karlc Posted February 12, 2006 Author Share Posted February 12, 2006 Hi AndyThank you very much for your help its working great. This was my first post in this forum in fact to any PHP forum I look forward to contributing in the near future as soon as I get my head around PHP a little more :)Would you mind if I posted the results of this in the webthang forum as I know some other ASP coders are keen on thisAgain much appreciated Quote Link to comment 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.