Jump to content

[SOLVED] $_SESSION quesstion


JJohnsenDK

Recommended Posts

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

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!";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.