如何将PHP用户/密码脚本修改为只需要密码


How to modify PHP user/password script to only require password

我已经搜索了几个星期,但找不到任何与这个特定问题相关的东西。

我有一个live.PHP的PHP页面。它成功地需要用户名和密码才能访问受保护的页面(livedata.PHP)。以下表单在live.PHP中:

<form name="LoginForm" form action="liveverify.php" method="post">
User Name:<input type="text" name="username" value="" />
Password:<input type="password" name="password" value="" />
<input type="submit" value="Login" /></p>
</form>

liveverify.php具有:

<?php
$usernames = array("user1, uer2, user3");
$passwords = array("pass1, pass2, pass3");
$page = "livedata.php";
for($i=0;$i<count($usernames);$i++) 
{  
$logindata[$usernames[$i]]=$passwords[$i];
}
$found = 0; for($i=0;$i<count($usernames);$i++) {    if ($usernames[$i] == $_POST["username"])        {    $found = 1;    } } if ($found == 0) {    header('Location: liveerror.php');    exit; }
if($logindata[$_POST["username"]]==$_POST["password"]){   session_start();   $_SESSION["username"]=$_POST["username"];   header('Location: '.$page);   exit;}else{   header('Location: liveerror.php');   exit;}?>

我的愿望是消除对用户名的需要,只需要一个有效的密码。我想我需要在liveverify.php中消除对用户名的引用。然而,我所尝试的一切都失败了。我感谢你的帮助。

忽略用户名似乎有点奇怪,但假设用户名仍将通过表单传递,您应该能够执行类似的操作

$passwords = array( "pass1", "pass2", "pass3" );
$page = "livedata.php";
if ( in_array($_POST["password"], $passwords) )
{
    session_start();
    $_SESSION[ "username" ] = $_POST[ "username" ];
    header( 'Location: ' . $page );
    exit;
}
else
{
    header( 'Location: liveerror.php' );
    exit;
}

这将允许用户名不匹配,并成为用户喜欢的任何东西,尽管