Closed Thread Icon

Topic awaiting preservation: session variables (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26760" title="Pages that link to Topic awaiting preservation: session variables (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: session variables <span class="small">(Page 1 of 1)</span>\

 
Hustluz
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2003

posted posted 09-30-2005 23:21

I'm building my admin page and im trying to make the login check for a registered user. it connects to the database and sees that the username and password is correct. but when i try to assign the username to a session variable ($logged_in_user) it doesnt log the variable into the session. this is my code.

code:
<? session_start()?> 

the html heards ect..
?>
//include file for connectino to database
	require ('./connection.php');
	//variables for links in the page
	$links = "<a href='main.php'>Click here to proceed to the main page</a><br><br><a href='logout.php'>Click here to log out.</a>";
	//user validation 
	if($_POST['user'] && $_POST['pass']){
		//check if user is already logged in
		if($logged_in_user == $_POST['user']){
			echo $_POST['user'].", you are already logged in.<br><br>";
			echo $links;
			exit;
		}
		//encrypting password
		$pw = md5($_POST['pass']);
		//sellectiong query from the users database
		$result = mssql_query("SELECT * FROM users 
				WHERE name = '".$_POST['user']."'
				AND password = '".$pw."'");
		//if connection is not made
		if(!$result){
			echo "Sorry, there has been a technical hitch. We cannot enter your data.";
			exit;
		}
		//if Login and Password is correct
		if(mssql_num_rows($result) > 0){
			$logged_in_user = $_POST['user'];
			$_SESSION['$logged_in_user'];
			echo "Welcome, ".$logged_in_user.".<br><br>";
			echo $links;
			exit;
		}
		//if Login or password is is incorrect this statment will echo out						
		echo "Your Login attemp has been uncsucessful.";
	//if both fields are not filled out
	}else if($_POST['user'] || $_POST['pass'] == 0){
		echo "Fill in Both Fields";
	}

?>
<form method="post" action="login.php">
Your username: 
<input name="user" type="text" maxlength="20" size="20" />
<br />
Your Password:
<input name="pass" type="password" maxlength="10" size="10" />
<br />
<input type="submit" value="Login" />
</form>

closing html tags...

if correct login and password the form takes you to the main page witch is...

<? session_start();)

html tags..

<?
	if(!$_SESSION['logged_in_user']){
		echo "<h3>Whoops!</h3><br>";
		echo "there has been an error.<br>";
		echo "<a href='login.php'>Click here to login.</a>";
		exit;
	}
	echo "Welcome, ".$logged_in_user.".";
?>


the variable doesnt carry over. does anyone know whats going one.

edit TP: added code tags for better readability.

(Edited by Tyberius Prime on 10-01-2005 10:24)

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 10-01-2005 01:08

you're using $_SESSION['$logged_in_user']

you want to do $_SESSION['logged_in_user'] = $logged_in_user;



.:[ Never resist a perfect moment ]:.

« BackwardsOnwards »

Show Forum Drop Down Menu