Jump to content

[SOLVED] My Problem with Sessions (Part 2)


Asperon

Recommended Posts

so the forms showed up the first time....but after that it won't work, I don't know if the session isn't destoying or what, I checked the recent post http://www.phpfreaks.com/forums/index.php/topic,151696.0.html for destroy sessions problems. I don't know what is wrong. I've been going over it for the past half an hour. its probably something dumb, but I can' seem to find it. the logout displays the array() and logged out data, so I know the sessions is destroyed.

 

login.php:

 

<?php
session_start();

if (isset($_POST['userName']) && isset($_POST['password']))
{
$userName = $_POST['userName'];
$password = $_POST['password'];

//connect to database

$link = mysql_connect('localhost', 'testUser', 'sra259') or die('Could not connect: ' . mysql_error());

mysql_select_db('iluvsocaldb') or die('Could not select database');

$query = 'SELECT * FROM administratorlogin WHERE userName="$userName" AND password="$password"';

$result = mysql_query($query);

$numRows = mysql_num_rows($result);

if($numRows > 0)
{
$_SESSION['validUser'] = $userName;
}

mysql_close($link);
}

?>

<html>
<head>
<title>ADMIN LOG IN</title>
</head>
<body>

<?

if(isset($_SESSION['validUser']))
{
echo $_SESSION['validUser']
}
else
{
  if (isset($userName))
  {
  echo 'Could not log you in.<br />';
  }
  else
  {
  echo 'You are not logged in.<br />';
  }

echo '<form action="logIn.php" method="POST">';
echo '<table>';
echo '<tr>';
echo '<td>User Name</td>';
echo '<td><input type="text" name="userName" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Password</td>';
echo '<td><input type="password" name="password" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="submit" value="LOG IN" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';

}

?>
<br/>
<a href="db_admin.php">Admins Only</a>
<a href="logout.php">Log Out</a>

</body>
</html>

 

db_admin.php:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head></head>
<body>
<?php
session_start();

if(isset($SESSION['validUser']))
{
echo '<h3><center>Welcome to the iluvsocal database editor</center></h3>';
echo '<table align="center">';
echo '<tr>';
echo '<td>';
echo '<form action="view_business.php" target="iframe" method="post">';
echo '<input type="submit" value="Businesses" />';
echo '</form>';
echo '</td>';
echo '<td>';
echo '<form action="view_salesRep.php" target="iframe" method="post">';
echo '<input type="submit" value="Sales Reps" />';
echo '</form>';
echo '</td>';
echo '</tr>';
echo '</table>';
echo '<iframe name="iframe" src="default.php" height="800" width="800" frameborder="0" allowtransparency="true"></iframe>';
}
else
{
echo '<h3>You are not authorized to view this page</h3>';
}
?>
</body>
</html>

 

logout.php:

 

<?php
session_start();
session_destroy();
print_r($_SESSION);
if(empty($_SESSION)){
?>
<html>
<body>

<p>logged out</p>
<a href="logIn.php">blahblah</a>


</body>
</html>
<?php
}
?>

Link to comment
Share on other sites

the first time I ran it , the login form appeared like it was supposed to, because no session had started, so I logged in, and it went to the db_admin.php page..that page didn't work, I probably still need to fix something I missed there, so  i went back and I did the logout, according to the script output, it destoyed the session, but the logIn.php file will not longer dispaly the form, it which means that it still thinks its logged in.

Link to comment
Share on other sites

the first time I ran it , the login form appeared like it was supposed to, because no session had started, so I logged in, and it went to the db_admin.php page..that page didn't work, I probably still need to fix something I missed there, so  i went back and I did the logout, according to the script output, it destoyed the session, but the logIn.php file will not longer dispaly the form, it which means that it still thinks its logged in.

 

 

I fixed the db_admin.php problem, that page says i'm logged out too, but the login page won't show the form still.

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.