Jump to content

Login System


neverett

Recommended Posts

For some reason... when running the following code the $_SESSION variable never gets set.  I always get "Your session is NOT working."

 

 

login.php

<?include("header.php");?>

<div id="content2-pagetitle">Member Management</div>
<div id="content-title-noshade-size2">Login</div>

<br>
<center>
<table align="center">
<form name="login" action="checklogin.php" method="post">
	<tr>
		<td>Email </td>
		<td><input type="text" name="email" size="25"></td>
	</tr><tr>
		<td>Password </td>
		<td><input type="password" name="password" size="25"></td>
	</tr>
</table>
<br>
<input type="submit" name="Login" value="Login" title="submit">
</form>
</center>
<?include("footer.php");?>

 

checklogin.php

<?ob_start();
include("functions.php");

$email = $_POST['email'];
$p = $_POST['password'];

if($email != "" && $p != ""){
	$pass = md5($p); // encrypt password
	$sql = "select * from users where email = '$email' and password = '$pass'";
	$result = mysql_query($sql) or die(mysql_error());
	$count = mysql_num_rows($result); // count the number of rows that were queried
	if($count == 1){
		$row = mysql_fetch_array($result);
		if($row['active'] == 1){
			@session_start();
			$_SESSION['user_id'] = $row['id'];
			$_SESSION['logged_in'] = true;
			sendredirect("http://www.ohiotrac.com/members/test.php");
		}else if($row['active'] == 0){?>
			<center>
			<b>Your membership was not activated.  Please open the confirmation email you received and click on the activation link.  Thank you.</b>
			</center>
		<?}
	}else{?>
		<center>
		<b>Your login could not be authenticated.  <a href="http://www.ohiotrac.com/members/login.php">Click here to login.</a></b>
		</center>
	<?}
}else{?>
	<center>
	<b>Please use your email address and password to login.  <a href="http://www.ohiotrac.com/members/login.php">Click here to login.</a></b>
	</center>
<?}
ob_end_flush();?>

 

test.php

<?@session_start();
include("header.php");
test();
include("footer.php");?>

 

functions.php [this file contains the test() function]

<?function test(){
	if($_SESSION['logged_in'] == false){
		echo "Your session is NOT working.<br><br>";
		echo $_SESSION['logged_in'];
	}else if($_SESSION['logged_in'] == true){
		echo "Your session is working.<br><br>";
		echo $_SESSION['logged_in'];
	}
}?>

Link to comment
https://forums.phpfreaks.com/topic/88311-login-system/
Share on other sites

Referring you test script .I would suggest that in your test.php do

$_SESSION['logged_in']=true;

and then make a call to your test() function and see if the session is working or not.

 

The test() function returns true and displays "Your session is working."  In other words, when I do that, it works.

Link to comment
https://forums.phpfreaks.com/topic/88311-login-system/#findComment-452000
Share on other sites

So is that solves your problem or not.???

 

Actually in your code you have not set the $_SESSION['logged_in'] anywhere hence when you run that test script you find nothing no error and no output.what i told you is to set the $session['logged_in'] and check so in if() condition it finds the condition to be true and displays the message to you.

Link to comment
https://forums.phpfreaks.com/topic/88311-login-system/#findComment-452080
Share on other sites

I have set $_SESSION['logged_in'] to true in checklogin.php.  It's there, I double checked.  It somehow gets lost when I sendredirect() to the test.php page.  I don't really like to send variables via the web address either (as I have considered doing that).  I don't know what is going wrong.  My redirect is a meta-refresh.  Thanks for everything!

Link to comment
https://forums.phpfreaks.com/topic/88311-login-system/#findComment-452385
Share on other sites

I noticed one place where I didn't have it, and I fixed it.  Still not working though.  Here is some updated code...

 

 

test.php

<?@session_start();
include("header.php");
test();
include("footer.php");?>

 

 

functions.php

<?function test(){
	@session_start();
	if($_SESSION['logged_in'] == false){
		echo "Your session is NOT working.<br><br>";
		echo $_SESSION['logged_in'];
	}else if($_SESSION['logged_in'] == true){
		echo "Your session is working.<br><br>";
		echo $_SESSION['logged_in'];
	}
}?>

 

 

login.php

<?include("header.php");?>

<div id="content2-pagetitle">Member Management</div>
<div id="content-title-noshade-size2">Login</div>

<br>
<center>
<table align="center">
<form name="login" action="checklogin.php" method="post">
	<tr>
		<td>Email </td>
		<td><input type="text" name="email" size="25"></td>
	</tr><tr>
		<td>Password </td>
		<td><input type="password" name="password" size="25"></td>
	</tr>
</table>
<br>
<input type="submit" name="Login" value="Login" title="submit">
</form>
</center>
<?include("footer.php");?>

 

 

checklogin.php

<?ob_start();
include("functions.php");

$email = $_POST['email'];
$p = $_POST['password'];

if($email != "" && $p != ""){
	$pass = md5($p); // encrypt password
	$sql = "select * from users where email = '$email' and password = '$pass'";
	$result = mysql_query($sql) or die(mysql_error());
	$count = mysql_num_rows($result); // count the number of rows that were queried
	if($count == 1){
		$row = mysql_fetch_array($result);
		if($row['active'] == 1){
			@session_start();
			$_SESSION['user_id'] = $row['id'];
			$_SESSION['logged_in'] = true;
			sendredirect("http://www.ohiotrac.com/members/test.php");
		}else if($row['active'] == 0){?>
			<center>
			<b>Your membership was not activated.  Please open the confirmation email you received and click on the activation link.  Thank you.</b>
			</center>
		<?}
	}else{?>
		<center>
		<b>Your login could not be authenticated.  <a href="http://www.ohiotrac.com/members/login.php">Click here to login.</a></b>
		</center>
	<?}
}else{?>
	<center>
	<b>Please use your email address and password to login.  <a href="http://www.ohiotrac.com/members/login.php">Click here to login.</a></b>
	</center>
<?}
ob_end_flush();?>

Link to comment
https://forums.phpfreaks.com/topic/88311-login-system/#findComment-452546
Share on other sites

So I changed some things to better test my sessions and still not working.  Here are the updated files (the login.php file remains the same as above)...

 

 

test.php

<?@session_start();
include("header.php");
if($_SESSION['logged_in'] == false){
	echo "Your session is NOT working in test.php.<br><br>";
	echo $_SESSION['logged_in'];
}else if($_SESSION['logged_in'] == true){
	echo "Your session is working in test.php.<br><br>";
	echo $_SESSION['logged_in'];
}
test();
include("footer.php");?>

 

 

functions.php

<?// start sessions
@session_start();
function test(){
	if($_SESSION['logged_in'] == false){
		echo "Your session is NOT working in functions.php.<br><br>";
		echo $_SESSION['logged_in'];
	}else if($_SESSION['logged_in'] == true){
		echo "Your session is working in functions.php.<br><br>";
		echo $_SESSION['logged_in'];
	}
}?>

 

 

checklogin.php

<?ob_start();
@session_start();
include("functions.php");

$email = $_POST['email'];
$p = $_POST['password'];

if($email != "" && $p != ""){
	$pass = md5($p); // encrypt password
	$sql = "select * from users where email = '$email' and password = '$pass'";
	$result = mysql_query($sql) or die(mysql_error());
	$count = mysql_num_rows($result); // count the number of rows that were queried
	if($count == 1){
		$row = mysql_fetch_array($result);
		if($row['active'] == 1){
			//@session_start();
			$_SESSION['user_id'] = $row['id'];
			$_SESSION['logged_in'] = true;
			sendredirect("http://www.ohiotrac.com/members/test.php");
		}else if($row['active'] == 0){?>
			<center>
			<b>Your membership was not activated.  Please open the confirmation email you received and click on the activation link.  Thank you.</b>
			</center>
		<?}
	}else{?>
		<center>
		<b>Your login could not be authenticated.  <a href="http://www.ohiotrac.com/members/login.php">Click here to login.</a></b>
		</center>
	<?}
}else{?>
	<center>
	<b>Please use your email address and password to login.  <a href="http://www.ohiotrac.com/members/login.php">Click here to login.</a></b>
	</center>
<?}
ob_end_flush();?>

 

 

Results

Your session is NOT working in test.php.

Your session is NOT working in functions.php.

Link to comment
https://forums.phpfreaks.com/topic/88311-login-system/#findComment-452595
Share on other sites

Still not working.

 

 

checklogin.php

<?@session_start();
ob_start();
include("functions.php");

$email = $_POST['email'];
$p = $_POST['password'];

if($email != "" && $p != ""){
	$pass = md5($p); // encrypt password
	$sql = "select * from users where email = '$email' and password = '$pass'";
	$result = mysql_query($sql) or die(mysql_error());
	$count = mysql_num_rows($result); // count the number of rows that were queried
	if($count == 1){
		$row = mysql_fetch_array($result);
		if($row['active'] == 1){
			//@session_start();
			$_SESSION['user_id'] = $row['id'];
			$_SESSION['logged_in'] = true;
			sendredirect("http://www.ohiotrac.com/members/test.php");
		}else if($row['active'] == 0){?>
			<center>
			<b>Your membership was not activated.  Please open the confirmation email you received and click on the activation link.  Thank you.</b>
			</center>
		<?}
	}else{?>
		<center>
		<b>Your login could not be authenticated.  <a href="http://www.ohiotrac.com/members/login.php">Click here to login.</a></b>
		</center>
	<?}
}else{?>
	<center>
	<b>Please use your email address and password to login.  <a href="http://www.ohiotrac.com/members/login.php">Click here to login.</a></b>
	</center>
<?}
ob_end_flush();?>

Link to comment
https://forums.phpfreaks.com/topic/88311-login-system/#findComment-452610
Share on other sites

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.