Note that there are some explanatory texts on larger screens.

plurals
  1. POphp script- Allow one session only at a time
    text
    copied!<p>Please help me to validate one session only at a time, kindly see the below script which currently allows the same username to login any number of sessions.</p> <p>I am not sure when and where to validate the session, help me in adding only those few lines which can validate the session for a username.</p> <pre><code>&lt;?php // accesscontrol.php include_once 'common.php'; include_once 'db.php'; session_start(); $uid = isset($_POST['uid']) ? $_POST['uid'] : $_SESSION['uid']; $pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd']; if(!isset($uid)) { ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;Login&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt; &lt;head&gt; &lt;style type="text/css"&gt; &lt;!-- .style1 { font-size: 16px; font-family: Verdana, Arial, Helvetica, sans-serif; } .style3 { font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif; } body { background-color: #D7F0FF; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } --&gt; &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;h1 class="style1"&gt; &lt;br&gt;&lt;br&gt;Amogh Site - Login Required &lt;/h1&gt; &lt;span class="style3"&gt;&lt;br&gt; You &lt;strong&gt;must login to access this area &lt;/strong&gt;of the site. &lt;br&gt; &lt;br&gt; If you are not a registered user, please contact your Admin to sign up for instant access!&lt;/span&gt; &lt;p&gt;&lt;form method="post" action="&lt;?=$_SERVER['PHP_SELF']?&gt;"&gt; &lt;span class="style3"&gt;User ID:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;input type="text" name="uid" size="12" /&gt; &lt;br&gt; &lt;br /&gt; Password:&lt;/span&gt; &lt;input type="password" name="pwd" SIZE="12" /&gt; &lt;br&gt; &lt;br /&gt; &lt;input type="submit" value="Login" /&gt; &lt;/form&gt;&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; &lt;?php exit; } $_SESSION['uid'] = $uid; $_SESSION['pwd'] = $pwd; dbConnect("hitek_svga3"); $sql = "SELECT * FROM user WHERE userid = '$uid' AND password = '$pwd'"; $result = mysql_query($sql); if (!$result) { error('A database error occurred while checking your '. 'login details.\\nIf this error persists, please '. 'contact you@example.com.'); } if (mysql_num_rows($result) == 0) { unset($_SESSION['uid']); unset($_SESSION['pwd']); ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt; Access Denied &lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt; &lt;style type="text/css"&gt; &lt;!-- .style1 { font-size: 16px; font-family: Verdana, Arial, Helvetica, sans-serif; } .style3 { font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif; } --&gt; &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;br/&gt; &lt;br/&gt; &lt;h1 class="style1"&gt; Access Denied &lt;/h1&gt; &lt;p class="style3"&gt;Your user ID or password is incorrect, or you are not a registered user on this site. To try logging in again, click &lt;a href="&lt;?=$_SERVER['PHP_SELF']?&gt;"&gt;here&lt;/a&gt;. To access, please contact our Admin !&lt;/a&gt;.&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; &lt;?php exit; } $username = mysql_result($result,0,'fullname'); $_SESSION['user'] = mysql_result($result,0,'userid'); $_SESSION['email'] = mysql_result($result,0,'email'); $_SESSION['notes'] = mysql_result($result,0,'notes'); ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload