473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

Jul 17 '05 #1
2 1647
You need to register the session variable before you set it, thus:
session_register("username");
$_SESSION['username'] = $username;
Kitty
http://OpenSkyWebDesign.com

Jul 17 '05 #2
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?

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Simon | last post by:
Hi, I have a Login.php page that logs the user in and out. I has two forms within the page, (depending on what we are trying to do), either one to log in or out. The form calls itself using a...
6
by: Astra | last post by:
Hi All I've noticed on quite a few ASP sites that when they have a 'MyAccount' section they transfer the site to https and then when you have logged into your account successfully and gone back...
12
by: ACaunter | last post by:
Hi all, I was wondering how i could write some code which would automatically open the Login Page once the session has expired? -- AdamPC@hotmail.com
3
by: Dave Smithz | last post by:
Hi there, I have a website where users can log into. This users sessions as I believe most people use when implementing a login section of a website (each php page first checks a valid parameter...
18
by: Gleep | last post by:
I've searched google intensely on this topic and it seems noone really knows how to approch this. The goal I don't want clients to give out their usernames and passwords to friends, since the site...
10
by: musosdev | last post by:
Wonder if someone can help! We're getting the following error on our Intranet system as soon as we login.. ------------------ Exception Details: System.Data.SqlClient.SqlException: Login...
14
by: knal | last post by:
Hi there, I'm looking for a secure login script for a sort-of-community site... (PHP, MySQL, sessions, or maybe something else ... ) I know there are a lot of scripts out there, but none of them...
6
by: pek | last post by:
I have read a lot of tutorials on how to create a login mechanism (a lot of which I found really useful). None of them however explain how do you check if the user is or is not in fact logged in. ...
9
by: Josh | last post by:
I run a Joomla website and am familiar with php in some but not all aspects. Currently I am trying to find some solutions related to session handling. Am I correct in saying that "login" is kept...
10
by: DavidPr | last post by:
When I logout as one user and log in under a different user, it opens with the last user's information. User 1 - Unsername: Davey Jones User 2 - Unsername: David Smith I log out from Davey...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.