|
Im having a problem, which in my head seems to be simple but i cannot
figure it out.
there are 3 pages.
Page 1 (login form)
page 2 (verifies login/pass and begins session. has link to page 3)
Page 3 (displays some info has a link back to page 2)
obviously i only want pages 2 and 3 to be able to be accessed through
the login.
i can get to page 2 and page 3 after login no problem but IF i press
the link on page 3 to page 2 it takes me back to page 1 and i have to
login again.
here is the code
Page 1 (admin.php)
......
<form method="post" action="edit_site.php">
Name: <input type="text" name="username">
Password: <input type="text" name="password">
<input type="submit" value="ENTER">
</form>
......
Page 2 (edit_site.php)
<?php
session_start();
$db_user = 'database_user';
$db_pass = 'database_password';
$username = $_POST['username'];
$password = $_POST['password'];
$connection = mysql_connect('localhost', $db_user, $db_pass) or
die(mysql_error());
mysql_select_db('database_main', $connection) or die(mysql_error());
$query = "SELECT * FROM users
WHERE username='$username' AND password='$password'";
$result = mysql_query($query, $connection) or die('error making
query');
$affected_rows = mysql_num_rows($result);
if($affected_rows == 1) {
$_SESSION['username'] = $username;
}
else {
header( "Location: admin.php" );
}
?>
Page 3 (edit_news.php)
<?php
session_start();
if(session_is_registered('username')){
echo 'Welcome, you are still logged in.';
}
else{
header( "Location: admin.php" );
}
?>
any help is GREATLY appreciated. thank you |