php设置用户名和密码

时间:2014-04-06 21:50:46

标签: php html

我一直在尝试设置登录系统,但无法设置我的用户名和密码。

<?php
session_start();
$user = “u1”;
$password = “p1”;
if ($_POST[‘username’] == $user ) &&
    ($_POST[‘password’] == $password) {
    echo welcome.php;
}
else echo you have entered the wrong credentials.
?>

3 个答案:

答案 0 :(得分:1)

这仅用于说明目的并回答此问题,但了解这不是一个安全的系统,不应在生产环境附近的任何地方使用 EVER < / p>

我认为,如果您设置ifelse语句,以及echo语句出现语法错误,可能会出现问题。尝试这样的事情:

<?php
session_start();
$user = 'u1';
$password = 'p1';
if ($_POST['username'] == $user  && $_POST['password'] == $password) {
  echo 'successfully logged in'; // changed to just show successful message
} else {
  echo 'you have entered the wrong credentials.'; // Placed quotes around echo statement
}
?>

答案 1 :(得分:0)

似乎是报价和支架问题。这应该对你有用:

<?php
    session_start();
    $user = "u1";
    $password = "p1";
    if (($_POST['username'] == $user ) && ($_POST['password'] == $password)) {
        echo welcome.php;
    }
    else echo "you have entered the wrong credentials".
?>

答案 2 :(得分:0)

替换

if ($_POST[‘username’] == $user ) && ($_POST[‘password’] == $password) {

if (($_POST[‘username’] == $user ) && ($_POST[‘password’] == $password)) {