简体   繁体   中英

php set username and password

I've been trying to set up a login system, but can't set my username and password.

<?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.
?>

This is only for illustrative purposes and to answer this question, but understand this is not a secure system and should not be used ANYWHERE EVER near a production environment!

I think it might be an issue with how you've set up your if and else statements, as well as you having a syntax error with the echo statement. Try something like this:

<?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
}
?>

It seems to be quotation and bracket problem. This should hopefully work for you:

<?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".
?>

Replace

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

with

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM