Forum Moderators: coopster
when user enter correct user id n passwd at the login page then he directed to home.php
Now problem occurs when i directly type home.php in the address bar.. how i can display the "session expired" page here when some 1 directly do this using address bar?
Plz help!
Thanks in advance!
start the session in both of your php file. in your login.php if the user give correct Username and Password the start the session like the below way
$_SESSION['username'] = $username ;
and in our home.php check if $_SESSION['username'] user name has any value or not. if it has then its okay and if it has not then generate error message
like
if($_SESSION['username']==''){
echo 'Oops you are not a valid user';
}
Thanks
Mahabub
<when username and password checks out, store them>
<?
session_start();
$_SESSION['uid'] = $uid;
?>
<inside home.php, check to see if this variable exists>
<?
session_start();
if(isset($_SESSION['uid'])){
//if user is logged in -> continue
}
else{
//user not logged in -> error handler here
}
?>
But it is not secure (if general security is required). Someone could spoof a session ID and gain access to another user/etc. If you want a "secure" login, you should employ a database to manage it. General idea: Store user data in DB (username, password, etc; remember to store the encrypted/hashed form of the password). When user logs in, authenticate user against database. Create session and store ID in database; as well as other relevant info such as IP address. Then to authenticate, grab the users session, check for it in the database, and confirm IPs match. In this method, it is harder for someone to "crack" in.
This is more complicated; and probably more than you need. Just wanted to make a note in case anyone else tries to employ the method. :)
Secondly, to do the method I noted requires a lot more code. I don't really have the personal time to write out how to do everything (sorry), but the following resources can help you learn and understand how to do it yourself (some of them you can download and use on your own site):
[php-login-script.com ]
[php.about.com ]
[devshed.com ]
Good luck! :)