好的,我试图创建一个简单的登录页面。
我可以成功完成但似乎我无法让多台计算机访问该页面。我在我的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 :(得分: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();
}
务必在session_start();
之前致电destroySession();
...会话+会话cookie消失。
答案 1 :(得分:0)
您可以尝试将会话添加到php页面,如:
session_start();
必须将其添加到php页面的顶部,一旦完成工作,请销毁会话:
session_destroy();
另外,请尝试关闭数据库连接:
$conn = NULL;
以上用于关闭数据库连接的代码适用于PHP PDO。如果您使用的是mysqli,请使用:
mysqli_close($conn);
顺便说一句,我从来没有遇到或听到过这样的问题。也许端口或一些不正确的参数导致问题?