注意:未定义的变量:第16行的/Applications/XAMPP/xamppfiles/htdocs/menthor/login.php中的电子邮件

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (39)

使用用户名登录应用程序时,不会使用该电子邮件,因此会抛出以下错误,反之亦然“注意:未定义的索引:第16行的/Applications/XAMPP/xamppfiles/htdocs/menthor/login.php中的电子邮件”

我已经尝试将产生错误的行放在条件中,但这些努力证明是徒劳的Login.php文件(与错误相关的部分)

// STEP 1. Receive data / info paassed to current file
if ((empty($_REQUEST['username']) || empty($_REQUEST['password'])) && (empty($_REQUEST['email']) || empty($_REQUEST['password']))) {
    $return['status'] = '400';
    $return['message'] = 'Missing requird information';
    echo json_encode($return);
    return;

} 


// securing received info / data from hackers or injections
$email = htmlentities($_REQUEST['email']);
$username = htmlentities($_REQUEST['username']);
$password = htmlentities($_REQUEST['password']);

// STEP 2. Establish connection with the server
require('secure/access.php');
$access = new access('localhost' , 'root', '' , 'menthor');
$access->connect();

// STEP 3. Check existence of the user. Try to fetch the user with the same email address
// STEP 3. Check availability of the login/user information
$username_aval = $access->selectUser_Username($username);
$email_aval = $access->selectUser_Email($email);

//$return = array();

// user is found
if ($username_aval) {

    // Get encrypted password and salt from the server for validation
    $encryptedPassword = $username_aval['password'];
    $salt = $username_aval['salt'];

    if ($encryptedPassword == sha1($password . $salt)) {

        $return['status'] = '200';
        $return['message'] = 'Successfully Logged In';
        $return['id'] = $username_aval['id'];
        $return['username'] = $username_aval['username'];
        $return['email'] = $username_aval['email'];
        $return['fullName'] = $username_aval['fullName'];
        $return['lastName'] = $username_aval['lastName'];
        $return['birthday'] = $username_aval['birthday'];
        $return['gender'] = $username_aval['gender'];
        $return['cover'] = $username_aval['cover'];
        $return['ava'] = $username_aval['ava'];
        $return['bio'] = $username_aval['bio'];
        $return['allow_follow'] = $username_aval['allow_follow'];

    } else {

        // In event that encrypted password and salt does not match
        $return['status'] = '201';
        $return['message'] = 'Password do not match';

    }

} else if ($email_aval) {

    // Get encrypted password and salt from the server for validation
    $encryptedPassword = $email_aval['password'];
    $salt = $email_aval['salt'];

    if ($encryptedPassword == sha1($password . $salt)) {

        $return['status'] = '200';
        $return['message'] = 'Successfully Logged In';
        $return['id'] = $email_aval['id'];
        $return['username'] = $email_aval['username'];
        $return['email'] = $email_aval['email'];
        $return['fullName'] = $email_aval['fullName'];
        $return['lastName'] = $email_aval['lastName'];
        $return['birthday'] = $email_aval['birthday'];
        $return['gender'] = $email_aval['gender'];
        $return['cover'] = $email_aval['cover'];
        $return['ava'] = $email_aval['ava'];
        $return['bio'] = $email_aval['bio'];
        $return['allow_follow'] = $email_aval['allow_follow'];

    } else {

        // In event that encrypted password and salt does not match
        $return['status'] = '202';
        $return['message'] = 'Password do not match';

    } 
}else {

        // In event that user is not found
        $return['status'] = '403';
        $return['message'] = 'User was not found';

}

// stop connection with server
$access->disconnect();

// pass info as JSON
echo json_encode($return);

Access.php文件(与错误相关的部分)将尝试根据收到的电子邮件选择数据库中的任何值

public function  selectUser_Email($email) {

    // array to store full user related information with the logic: key=>Value
    $returnArray = array();

    // SQL Language / Commande to be sent to the server
    // SELECT * FROM users WHERE email='rondell@gmail.com'
    $sql = "SELECT * FROM users WHERE email='" . $email . "'";

    // executing query via already established connection with the server
    $result = $this->conn->query($sql);

    // result isn't zero and it has least 1 row / value / result
    if ($result != null && (mysqli_num_rows($result)) >= 1) {

        // converting to JSON
        $row = $result->fetch_array(MYSQLI_ASSOC);

        // assign fetched row to ReturnArray
        if (!empty($row)) {
            $returnArray = $row;
        }
    }

    // throw back returnArray
    return $returnArray;
}

// Will try to select any value in the database based on received Email
public function  selectUser_Username($username) {

    // array to store full user related information with the logic: key=>Value
    $returnArray = array();

    // SQL Language / Commande to be sent to the server
    // SELECT * FROM users WHERE username='rondell'
    $sql = "SELECT * FROM users WHERE username='" . $username . "'";

    // executing query via already established connection with the server
    $result = $this->conn->query($sql);

    // result isn't zero and it has least 1 row / value / result
    if ($result != null && (mysqli_num_rows($result)) >= 1) {

        // converting to JSON
        $row = $result->fetch_array(MYSQLI_ASSOC);

        // assign fetched row to ReturnArray
        if (!empty($row)) {
            $returnArray = $row;
        }
    }

    // throw back returnArray
    return $returnArray;
}

通过Web服务器登录时的当前结果

Notice: Undefined index: email in /Applications/XAMPP/xamppfiles/htdocs/menthor/login.php on line 16
{"status":"200","message":"Successfully Logged In","id":"44","username":"rondell","email":"rondell@gmail.com","fullName":"rondell","lastName":"","birthday":"","gender":"","cover":"","ava":"","bio":"","allow_follow":"1"}

预期成绩

{"status":"200","message":"Successfully Logged In","id":"44","username":"rondell","email":"rondell@gmail.com","fullName":"rondell","lastName":"","birthday":"","gender":"","cover":"","ava":"","bio":"","allow_follow":"1"}
提问于
用户回答回答于

使用电子邮件作为对象,或者您可以转储请求并查看发生的情况

热门问答

关于Linux DNS服务器设置问题?

mariolu

腾讯 · 后台开发工程师 (已认证)

CDN及云从业者
推荐

CNAME到XX.com,这个XX.COM本身也是需要能解析ip的。CNAME到XX.COM的意义是你能解析到CDN厂商A的域名XX.COM或者CDN厂商B的域名YY.COM。所以需要提供服务的CDN厂商给你他们的域名。这样,DNS查询链路才是完整的。

我刚申请的服务器,缺省给我的是linux,可我要Windows,怎么办?

蒋小爱

腾讯云 · 技术支持 (已认证)

推荐
云服务器提供 不同平台重装:仅支持中国大陆地区(不含中国香港)。 例如,Linux 重装为 Windows,Windows 重装为 Linux 。 参考 重装系统: https://cloud.tencent.com/document/product/213/4933 图片.p...... 展开详请

云服务器不能访问外部网站?

HappyLau谈云计算

腾讯云 · 云计算高级工程师 (已认证)

专注于公有云,私有云解决方案,在kubernetes,openstack,kvm,ceph,linux,shell有丰富的实战经验。
推荐
不能访问外部网站一般是网络和dns的问题,按照如下步骤排查: 1. 确保CVM有外网ip或者NAT转换,使用ping测试下外网的连通性,如果不通请购买弹性公网IP,先申请后购买参考https://cloud.tencent.com/document/product/215/201...... 展开详请

合作伙伴学院里的学习视频测试题和在线培训系统里的测试题能否提供答案?

骑牛看晨曦love&peace~
推荐

http://tencentcloudxuexi.com 合作伙伴可以登录此平台做练习题,有答案的喔

两台腾讯云的服务器在同一个地区,内网网段也相同,都是172.17.0.X,为啥ping内网地址不通?

HappyLau谈云计算

腾讯云 · 云计算高级工程师 (已认证)

专注于公有云,私有云解决方案,在kubernetes,openstack,kvm,ceph,linux,shell有丰富的实战经验。
推荐已采纳

首先看下两台机器是否在同个vpc内,在同个vpc内默认网络可以互通,如果不在同个vpc内需要通过对等连接或者云联网打通,如果在同个vpc下无法互通,请检查下安全组和os的防火墙规则,放行icmp连接。

腾讯服务器怎么回事?怎么突然就无法连接了?

HappyLau谈云计算

腾讯云 · 云计算高级工程师 (已认证)

专注于公有云,私有云解决方案,在kubernetes,openstack,kvm,ceph,linux,shell有丰富的实战经验。
推荐
无法登录的原因有很多,可以按照如下步骤检查: 1. 通过vnc登录,检查系统是否启动 2. 检查操作系统的防火墙iptables或windows防火墙 3. 检查安全组是否放行了登录端口和icmp 按照上述步骤排查,大部分问题都可以解决。... 展开详请

扫码关注云+社区

领取腾讯云代金券