i trying to write a script so that it does,nt allow the user to login again if already logged in...whether he tries from other browser..................
wat i m doing is setting a value in database to 1 if he logs in and 0 if he logs out .......den i check this value on login page to inform him that he is already logged in......but the problem is if user closes the window without logging out .....it shows them dat they are already logged in....... but wat to do to make them login again...........

Use Sessions for authentication. They will log the user off when the browser is closed. You shouldn't need to store a value in the db unless you want to show users activity (last login at...)

Sessions would work the best for this, if you add <? session_start(); ?> at the very beginning of your script. You can set a session variable by simply adding a value to it. For example your script may look like this:

This is how to set the session var:

<?php
session_start();
//once the user is logged in via your current script you can set the $_SESSION['login'] var
//get a random string of characters
$var = md5(date("mdyhis"));
//set the session variable with that random string
$_SESSION['login'] = $var;
?>

This would be the verification that the session exists:

<?php
session_start();

//check if the session exists
if($_SESSION['login'])
{
//this means they are logged in, all your code can go here, or maybe a 
//redirect to the protected area.
}
else
{
//here you would output the login form, or redirect to the login
}
?>

Note: the <?php session_start(); ?> needs to be at the very beginning of you code

commented: it he;ped me a lot +1

Note: the <?php session_start(); ?> needs to be at the very beginning of you code

No whitespaces and echo statements also.

i got it.......
thank you all very much..............

its all done

Can you please paste the sample code of your solution. I need this to integrate in my site.

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.