JJohnsenDK Posted May 9, 2007 Share Posted May 9, 2007 Hey Im trying to make a dynamic languages script, where the user can change the languages on the website by clicking a link. I have maincore.php where i select the languages (Dont mind the bad spelled langues, i mean languages): <?php if(!isset($_SESSION['langues'])){ $_SESSION['langues'] = 2; } $langues = $_SESSION['langues']; $settingsQuery = mysql_query("SELECT langues FROM settings WHERE settings_id = '$langues'"); $settings = mysql_fetch_array($settingsQuery); define("LOCALE", BASEDIR."langues/"); define("LANGUES", $settings['langues']."/"); ?> Then i have the lan.php file where the $_SESSION should be reset to the languages the user have choosed: <?php session_start(); if(isset($_SESSION['langues'])){ session_unset(); session_destroy(); $_SESSION['langues'] = $_GET['langues']; header("location:login.php"); exit(); }else{ echo "ERROR!"; } ?> At last i have a sample login page where the user can choose the languages: <?php session_start(); require_once("../maincore.php"); include LOCALE.LANGUES."login.php"; if(isset($_POST['login_submit'])){ $username = $_POST['username']; $password = $_POST['password']; $checkQuery = mysql_query("SELECT username, password FROM users WHERE username = '$username' AND password = '$password'"); $checkRow = mysql_fetch_row($checkQuery); if($checkRow > 0){ $_SESSION['username'] = $username; $_SESSION['status'] = 'logged'; header("location:".BASEDIR."index.php"); exit(); }else{ $_SESSION['status'] = 'not logged'; echo $langues['001']; } } echo $lan['005']." ---- ".$_SESSION['langues']; echo "<a href='lan.php?langues=1'>".$lan['006']."</a>"; echo "<br />"; echo "<a href='lan.php?langues=2'>".$lan['007']."</a>"; ?> <form action='<?php $_SERVER['PHP_SELF']; ?>' method='POST'> <p> <?php echo $lan['002']; ?><br /> <input type='text' name='username' value='' /> </p> <p> <?php echo $lan['003']; ?><br /> <input type='password' name='password' value='' /> </p> <p> <input type='submit' name='login_submit' value='<?php echo $lan['004'];?>' /> </p> </form> I think the problem lies in the lan.php file, because it seems to kill the $_SESSION but then it doesnt set it to $_GET['langues']; Hope someone can help. Link to comment https://forums.phpfreaks.com/topic/50686-solved-_session-quesstion/ Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 9, 2007 Share Posted May 9, 2007 Well, for one you don't need to start the session over again...if you start it once then it's active no matter where in your domain you go...until you close the browser or manually end the session. Link to comment https://forums.phpfreaks.com/topic/50686-solved-_session-quesstion/#findComment-249156 Share on other sites More sharing options...
mpharo Posted May 9, 2007 Share Posted May 9, 2007 actully on any page where you using sessions (unless it is an embedded page) you need the session_start().... try using the unset($_SESSION['langues']); function instead of killing the session with session_destroy(); Link to comment https://forums.phpfreaks.com/topic/50686-solved-_session-quesstion/#findComment-249161 Share on other sites More sharing options...
JJohnsenDK Posted May 9, 2007 Author Share Posted May 9, 2007 Thats what i thought... anyways, any suggentions on the problem? Link to comment https://forums.phpfreaks.com/topic/50686-solved-_session-quesstion/#findComment-249164 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 9, 2007 Share Posted May 9, 2007 Try this... $_SESSION['langues'] = $_GET['langues']; session_write_close(); header("location:login.php"); Link to comment https://forums.phpfreaks.com/topic/50686-solved-_session-quesstion/#findComment-249176 Share on other sites More sharing options...
mpharo Posted May 9, 2007 Share Posted May 9, 2007 What you need to do if you resetting a session variable to another value is use the unset(); function to clear the value of it...then reset it to the value... <?php session_start(); if(isset($_SESSION['langues'])){ unset($_SESSION['langues']); $_SESSION['langues'] = $_GET['langues']; header("location:login.php"); exit(); }else{ echo "ERROR!"; } ?> Link to comment https://forums.phpfreaks.com/topic/50686-solved-_session-quesstion/#findComment-249178 Share on other sites More sharing options...
JJohnsenDK Posted May 9, 2007 Author Share Posted May 9, 2007 That worked... That alot mpharo Link to comment https://forums.phpfreaks.com/topic/50686-solved-_session-quesstion/#findComment-249188 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.