Dark Angel 0 Posted November 21, 2004 Share Posted November 21, 2004 Hello. I'm learning PHP right now. I'm trying to pass a session var named "sessLang" which of course is the language chosen by visitors. I have an entrance page (http://www.adnddownloads.com/testphp/language.php) where you choose your language. When none is choose, default is english. I'm trying to pass the seeLang var en its value by the URL as you can see when you click on a flag or another. But it just doesn't work. One thing is I don't know if can't do it that way... Anyway, even if you select French, you'll see that the language stays in english (default language). Could anyone tell me what I have to do to affect the value of the session var sessLang when a user clicks on one of the two flags on my entrance page. Thanks a lot! I thought you my want to see my code: ------------------------------------- <?php session_start(); session_register("sessLang"); ?> <html> <head> <title>Essais en PHP</title> <?php include('Style.inc'); ?> </head> <body text='#FFFFFF' bgcolor='#061525'> <div align='center'> <center> <table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' width='100%' id='AutoNumber1' height='100%'> <tr> <td width='100%'> <p align='center'> <br> <img border="0" src="entrance01.jpg" width="880" height="125"><br> <a href="classes.php?sessLang=english"> <img border="0" src="entrance02.jpg" width="441" height="285"></a><a href="classes.php?sessLang=french"><img border="0" src="entrance03.jpg" width="439" height="285"></a></td> </tr> </table> </center> </div> </body> </html> Quote Link to post Share on other sites
Dark Angel 0 Posted November 21, 2004 Author Share Posted November 21, 2004 Come on! No one here can help me with this problem that must be very simple?... Maybe this might help you : the only thing I want to do is when you click on a flag, it sets the session variable "sessLang" to english or french and thenthis value is kept during the whole session. That's it. I'm sure there's at least one person here who knows PHP! Help me! Quote Link to post Share on other sites
TCH-Don 0 Posted November 21, 2004 Share Posted November 21, 2004 A few hours for a reply on a saturday night does not mean no one knows, any that may just are not here yet. Give it a little time. I looking at the php manual I do see ><?php // Use of session_register() is deprecated $barney = "A big purple dinosaur."; session_register("barney"); // Use of $_SESSION is preferred, as of PHP 4.1.0 $_SESSION["zim"] = "An invader from another planet."; // The old way was to use $HTTP_SESSION_VARS $HTTP_SESSION_VARS["spongebob"] = "He's got square pants."; ?> I wonder if the part // Use of session_register() is deprecated makes a difference? I can't help more than that as I do not see how the session var is defined? in classes.php maybe, but I am still trying to learn sessions too, so you will need to wait for others to help. Quote Link to post Share on other sites
mattisl 0 Posted November 21, 2004 Share Posted November 21, 2004 Try putting this code at the start of the classes.php file: >// Start session session_start(); // Get selected language from url switch($_GET["sessLang"]) { default: // No language has been selected case "english": // English has been selected $_SESSION["sessLang"] = "english"; break; case "french": // French has been selected $_SESSION["sessLang"] = "french"; break; } Now the language value is stored in the element "sessLang" in the $_SESSION array. You will also need to put session_start(); at the beginning on every page where you want to get access to the $_SESSION array. Quote Link to post Share on other sites
Dark Angel 0 Posted November 21, 2004 Author Share Posted November 21, 2004 Mattisl, your code turned out to work pretty well. I was aware of the use of neither the $_SESSION array and the $_GET function. This will help me a lot! Thanks again! Quote Link to post Share on other sites
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.