Simple Php Problem

windows

Guest
Hello.<br /><br />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.<br /><br />I have an entrance page (<!-- m --><a class="postlink" href="http://www.adnddownloads.com/testphp/language.php">http://www.adnddownloads.com/testphp/language.php</a><!-- m -->) 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...<br /><br />Anyway, even if you select French, you'll see that the language stays in english (default language).<br /><br />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.<br /><br />Thanks a lot!<br /><br /><br /><br />I thought you my want to see my code:<br /><br />-------------------------------------<br /><br /><?php<br />session_start();<br />session_register("sessLang");<br />?><br /><br /><html><br /><head><br /><title>Essais en PHP</title><br /><br /><?php include('Style.inc'); ?><br /><br /></head><br /><body text='#FFFFFF' bgcolor='#061525'><br /><br /><div align='center'><br /><center><br /><table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' width='100%' id='AutoNumber1' height='100%'><br /><tr><br /><td width='100%'><br /><p align='center'><br /><br><br /><img border="0" src=http://www.totalchoicehosting.com/forums/lofiversion/index.php/"entrance01.jpg" width="880" height="125"><br><br /><a href=http://www.totalchoicehosting.com/forums/lofiversion/index.php/"classes.php?sessLang=english"><br /><img border="0" src=http://www.totalchoicehosting.com/forums/lofiversion/index.php/"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><br /></tr><br /></table><br /></center><br /></div><br /><br /><br /></body><br /></html><!--content-->
Come on! No one here can help me with this problem that must be very simple?...<br /><br />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.<br /><br />I'm sure there's at least one person here who knows PHP! Help me!<!--content-->
A few hours for a reply on a saturday night does not mean no one knows,<br />any that may just are not here yet.<br />Give it a little time.<br /><br />I looking at the php manual I do see<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br />// Use of session_register() is deprecated<br />$barney = "A big purple dinosaur.";<br />session_register("barney");<br /><br />// Use of $_SESSION is preferred, as of PHP 4.1.0<br />$_SESSION["zim"] = "An invader from another planet.";<br /><br />// The old way was to use $HTTP_SESSION_VARS<br />$HTTP_SESSION_VARS["spongebob"] = "He's got square pants.";<br />?><!--c2--></div><!--ec2--><br /><br />I wonder if the part<br />// Use of session_register() is <!--coloro:#FF0000--><span style="color:#FF0000"><!--/coloro-->deprecated<!--colorc--></span><!--/colorc--><br />makes a difference?<br />I can't help more than that as I do not see how the session var is defined?<br />in classes.php maybe, but I am still trying to learn sessions too,<br />so you will need to wait for others to help.<!--content-->
Try putting this code at the start of the classes.php file:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->// Start session<br />session_start();<br /><br />// Get selected language from url<br />switch($_GET["sessLang"])<br />{<br /> ?default: ??????/ No language has been selected<br /> ?case "english": ??// English has been selected<br /> ???#036;_SESSION["sessLang"] = "english";<br /> ??鐕絩eak;<br /> ?case "french": ???/ French has been selected<br /> ???#036;_SESSION["sessLang"] = "french";<br /> ??鐕絩eak;<br />}<!--c2--></div><!--ec2--><br /><br />Now the language value is stored in the element "sessLang" in the $_SESSION array. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><br /><br />You will also need to put <!--coloro:blue--><span style="color:blue"><!--/coloro-->session_start();<!--colorc--></span><!--/colorc--> at the beginning on every page where you want to get access to the $_SESSION array.<!--content-->
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!<!--content-->
 
Back
Top