Connecting Tech Pros Worldwide Help | Site Map

Login php sessions

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 12:53 PM
Quinonez
Guest
 
Posts: n/a
Default Login php sessions

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


  #2  
Old July 17th, 2005, 12:53 PM
MsKitty
Guest
 
Posts: n/a
Default Re: Login php sessions

You need to register the session variable before you set it, thus:
session_register("username");
$_SESSION['username'] = $username;


Kitty
http://OpenSkyWebDesign.com

  #3  
Old July 17th, 2005, 12:54 PM
Quinonez
Guest
 
Posts: n/a
Default Re: Login php sessions

i entered that here

Page 2 (edit_site.php)
.....
if($affected_rows == 1) {
session_register("username");
$_SESSION['username'] = $username;
}
else {
header( "Location: admin.php" );
}

?>

doesnt work? is that correct, Shouldnt there be something when i come
back that checks if the session is still good?

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.