2015-02-06 145 views
0

好吧,我正在尝试创建一个简单的登录页面。有没有办法从sql数据库中注销?

我可以成功地做到这一点,但似乎我无法让多台电脑访问该页面。我在我的mysql数据库上创建了多个不同的用户,他们单独凭证进入并查询它的数据,但是只有一台计算机似乎会放入。

我也设置了PHP会话变量包含登录信息。

我简单的问题是:

是否有一个退出的分贝和销毁我的会议或许让其他计算机访问的用户名一个已经完成

后,它可能是会议的方式或数据库登录仍然徘徊在一台正在造成这种情况的计算机?

我知道我的代码是一个烂摊子:

<?php session_start(); 
    include("password.php"); ?> 
    ... 
    <body> 

<div class="main_content"> 
<?php 
    $submenarray = array(
    'Purpose' => 'purpose.php', 
    'Leading Self' => 'leadingself.php', 
    'Leading with Strategy' => 'leadingwithstrategy.php', 
    'Leading People' => 'leadingpeople.php', 
    'Leading for Results' => 'leadingforresults.php', 
    ); 

    insert_header_with_params(0,0,$submenarray); 
?> 

<div class="content_body"> 
    <div class="description"> 
    <h1 style="margin-left:5%;"> 
    User <span style="color:red"> Login</span> 
    </h1> 
    <p></p> 
    </div> 




<? 
    global $USERS; 
    global $_SESSION; 
    $USERS= getUsers("member1","password"); 
    $record; 
    $max_login_attempts = 3; 



    if(isset($_POST['password'])){$_SESSION["password"] = $_POST["password"];} 

    if($_GET["logged"] == "false"){ 
    $_SESSION["logged"] = ""; 
    } 

    if(isset($_POST['Field1'])){ 
    $record = getRecord($_POST["Field1"],removeUnwantedChar($_POST["Field1"]),$_POST["password"]);} 


if ($_POST["ac"]=="log") { /// do after login form is submitted 
    if ($record[19]==$_POST["password"]) { 
     $_SESSION["logged"]=$_POST["Field1"]; 
     $sql = "UPDATE `leading_initiatives` SET `Login Attempts`='0' 
      WHERE `Name`='".$_POST['Field1']."'"; 
      sql_command($sql,removeUnwantedChar($_POST["Field1"]),$_POST["password"]); 

    } else { 
     if($record[20] < $max_login_attempts){ 
     setRecord('Login Attempts',$record[20]+1,$record[1],removeUnwantedChar($_POST["Field1"]),$_POST["password"]); 
     echo '<p style="padding-left:20%;">Incorrect username/password. '.($max_login_attempts-$record[20]).' attempts remaining.</p>'; 
     }else{ 
     echo 'max reached'; 
    } 
    } 
} 

    $attempts = $record[20]; 
    if($attempts > $max_login_attempts) 
    $_SESSION["locked_out"] = "true"; 

if (array_key_exists($_SESSION["logged"],$USERS)) { //// check if user is logged or not 
    echo "<p style='padding-left:20%;'>Logged in: ".$_SESSION["logged"]."</p>"; //// if user is logged show a message 
    echo "<a href='http://newsite.com' style='padding-left:20%;'>form</a></br></br>";  
}elseif($_SESSION["locked_out"] == "true"){ 
    echo "<script> 
    window.location.replace('site/max_attempts.php'); 
    </script>"; 
} 
    else { //// if not logged show login form 
     echo '<form id="the_form" name="the_form" action="http://site/login.php" method="post" style="padding-left:20%;"> 
    <input type="hidden" name="ac" value="log">'; 
    echo 'Username: <select id="Field1" name="Field1"> 
     <option value=""></option> 
     <option value="Admin">Admin</option> 
     <option value="Anton, Manny">Anton, Manny</option> 
    </select>'; 
    echo 'Password: <input type="password" name="password" id="password" />'; 
    echo '<input type="submit" value="Login" />'; 
    echo '</form>'; 
} 


    if($_GET["logged"] == "false"){ 
    echo "<script>document.forms['the_form']['Field1'].value = ".$_GET["Field1"].";</script>"; 
    } 
    ?> 



    </div> <!--end content body--> 



    </div> <!--end the main content div--> 

</body> 
​ 
+0

你能跟我们分享一些代码吗?这里听起来很奇怪。 – 2015-02-06 13:30:00

+0

连接到数据库时,多个用户可以共享相同的凭据。简单来说,这不是数据库上的问题。它看起来像一个更大的问题。你说只有一个用户可以访问你的“db”。这可能是因为你在Web服务器的HTTP管道“功能”上停滞不前。 – 2015-02-06 13:47:04

回答

0

有很多种方法来摧毁一个会话。这是一个非常彻底:

// destroy session the correct way 
function destroySession() { 
    $_SESSION = array(); 
    if (ini_get('session.use_cookies')) { 
     $params = session_get_cookie_params(); 
     setcookie(session_name(), '', time() - 42000, 
      $params['path'], $params['domain'], $params['secure'], $params['httponly'] 
     ); 
    } 
    session_destroy(); 
} 

务必destroySession();之前调用session_start(); ...和会话+会话cookie消失。

+0

你一定是对的。为什么将cookie设置为这些值,我不想让它们为空或空?你介意解释一下这些功能在做什么吗?另外,我不能只是简单地调用session_destroy? – 2015-02-06 13:30:19

+0

session_destroy()可以正常工作,但会话ID保留在cookie中,如果您使用其他任何cookie,则其他任何情况都会如此。它所做的是循环访问每个cookie,并将其设置为过期,这与删除我们可以获取的cookie差不多。 – neokio 2015-02-06 13:34:31

0

你可以尝试加入会议的PHP页面,如:

session_start(); 

必须在PHP页面的顶部加入,一旦工作完成后,破坏了会议:

session_destroy(); 

此外,请尝试关闭数据库连接:

$conn = NULL; 

上面的代码用于关闭数据库连接i s用于PHP PDO。如果您使用的是mysqli,请使用:

mysqli_close($conn); 

顺便说一句,我从来没有遇到或听说过这样的问题。也许端口或一些不正确的参数导致这个问题?

相关问题