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
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.