FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


User Authentication





abhinav_shah
I have a php script for authenticating users. But there is a problem.
When a user logs in with his username and password he can access the restricted pages. But what i want to do is, if a user presses back button then the user should get logged off. I'm using php.
Here is the code for login page....

Code:
<?
session_start();
include("head.inc");
$mysql = mysql_connect("localhost","abhinavs","");
$uname = $_POST["uname"];
$pass = $_POST["pass"];
$result = mysql_db_query("abhin****","select *from pass where uname='$uname' and pass='$pass'");
$affected_rows = mysql_num_rows($result);
if($affected_rows == 1) {
      print "<h2>$uname, You are now logged in</h2>";
      $_SESSION['user_name'] = $uname;
   }

   else {
      print '<h2>Incorrect username or password. Please try logging-in again</h2>';
      include("menu.inc");
      die();
   }


http://www.abhinav.frih.net
arch23
hmm... don't know if you can identify a back button push, maybe you can.
anyway, pressing back should always get you to the same page you logged in from. so log the user off on the start of the page...
SirDuncan
hi,

why do you want to logout the user when it uses the back button ?

I suggest to check the session status at the beginning of each page, for example, checking the value of de $_SESSION['user_name'] variable. If the variable is not set properly the user is logged out

a suggestion: you can use this query:
"select count(*) from pass where uname='$uname' and pass='$pass'"
instead of "select *...."
Related topics
User Authentication based Menu Panel
Authentication Module
Forum
[COMMUNITY PROJECT]Frihost Forum
Simple login system
Secure website with password?
Site Members' System
A very good PHP MySQL Tutorial
what is better? Sessions or Cookies
WHat is the best PHP guidebook?
Windows XP SP3 comming soon
FTP
How to create a login on Dreamweaver 8
register/login mysql
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.