<small id='bcQxt'></small><noframes id='bcQxt'>

<tfoot id='bcQxt'></tfoot>
  • <legend id='bcQxt'><style id='bcQxt'><dir id='bcQxt'><q id='bcQxt'></q></dir></style></legend>

          <bdo id='bcQxt'></bdo><ul id='bcQxt'></ul>
      1. <i id='bcQxt'><tr id='bcQxt'><dt id='bcQxt'><q id='bcQxt'><span id='bcQxt'><b id='bcQxt'><form id='bcQxt'><ins id='bcQxt'></ins><ul id='bcQxt'></ul><sub id='bcQxt'></sub></form><legend id='bcQxt'></legend><bdo id='bcQxt'><pre id='bcQxt'><center id='bcQxt'></center></pre></bdo></b><th id='bcQxt'></th></span></q></dt></tr></i><div id='bcQxt'><tfoot id='bcQxt'></tfoot><dl id='bcQxt'><fieldset id='bcQxt'></fieldset></dl></div>

      2. PHP 会话的未定义索引

        Undefined index with PHP sessions(PHP 会话的未定义索引)

              <tbody id='eKW7q'></tbody>
          1. <i id='eKW7q'><tr id='eKW7q'><dt id='eKW7q'><q id='eKW7q'><span id='eKW7q'><b id='eKW7q'><form id='eKW7q'><ins id='eKW7q'></ins><ul id='eKW7q'></ul><sub id='eKW7q'></sub></form><legend id='eKW7q'></legend><bdo id='eKW7q'><pre id='eKW7q'><center id='eKW7q'></center></pre></bdo></b><th id='eKW7q'></th></span></q></dt></tr></i><div id='eKW7q'><tfoot id='eKW7q'></tfoot><dl id='eKW7q'><fieldset id='eKW7q'></fieldset></dl></div>
            <tfoot id='eKW7q'></tfoot>
                <bdo id='eKW7q'></bdo><ul id='eKW7q'></ul>

                <small id='eKW7q'></small><noframes id='eKW7q'>

                  <legend id='eKW7q'><style id='eKW7q'><dir id='eKW7q'><q id='eKW7q'></q></dir></style></legend>
                  本文介绍了PHP 会话的未定义索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 PHP 新手,在会话方面更是初学者.我有我的 index.php 页面,用户可以在其中注册和登录.表单分别发布到 validate.php 和 loginvalidate.php 页面,用于注册和登录.

                  I'm new to PHP and am even more of a beginner when it comes to sessions. I have my index.php page, which is where users can register and login. The forms are posting to validate.php and loginvalidate.php pages, respectively for registering and logging in.

                  我在加载 index.php 时出现以下错误:

                  I have these errors on index.php when I load it:

                  1) 注意:未定义索引:已注册2)注意:未定义的索引:从未使用过

                  1) Notice: Undefined index: registered 2) Notice: Undefined index: neverused

                  我尝试过以多种方式修改我的文本,但始终无法解决错误.

                  I have tried modifying my text in many ways but I never got to solve the errors.

                  索引.php

                      <?php
                              if ($_SESSION['registered'] != NULL){
                                  echo $_SESSION['registered'];                   
                              }
                              if ($_SESSION['badlogin'] != NULL){
                                  echo $_SESSION['badlogin'];
                              }
                              if ($_SESSION['neverused'] != NULL) {
                                  echo $_SESSION['neverused'];                    
                              }
                      ?>
                  

                  Validate.php(提交注册表后)

                  Validate.php (after submitting register form)

                      if (mysqli_num_rows($result) > 0) {  //IF THERE IS A PASSWORD FOR THAT EMAIL IN DATABASE
                      $_SESSION['registered'] = "Email is already registered.";
                      mysqli_close($db_handle);
                      header('Location: index.php');
                      exit();
                  }
                  

                  Loginvalidate.php(提交登录表单后)

                  Loginvalidate.php (after submitting login form)

                  if ($numrows!=0)  //IF THERE IS A PASSWORD FOR THAT EMAIL IN THE DATABASE
                  {
                    if ($row['password'] == $password) {  //IF THE PASSWORD MATCHES USER INPUT
                        header('Location: homepage.php');
                        echo "lol";
                        exit();
                    }
                    else{
                      $_SESSION['badlogin'] = "Email/password combination not valid.";
                      mysqli_close($db_handle);
                      header('Location: index.php');
                      exit();
                    } 
                  }
                  else {  //THERE IS NO PASSWORD FOR THAT EMAIL, SO THAT EMAIL IS NOT REGISTERED
                      $_SESSION['neverused'] = "Email is not registered.";
                      mysqli_close($db_handle);
                      header('Location: index.php');
                      exit();
                  }
                  

                  好的,所以我的脚本执行了预期的操作.我唯一无法解决的是这些会话错误.您是否看到任何滥用会话的情况?当然,我已经在所有 .php 文件中启动了会话.

                  Okay so my script does what it is intended to do. The only thing that I can't solve is these session errors. Do you see any misuse of sessions? Of course, I have started the sessions in all of my .php files.

                  另外,请注意,我知道没有针对黑客的保护措施.这仅适用于不包含任何重要数据的未来原型.

                  Also, note that I am aware that there is no protection from hackers. This is only for a future prototype that won't contain any important data.

                  推荐答案

                  出现这些错误的原因是您正在尝试读取不存在的数组键.isset() 函数在那里,因此您可以对此进行测试.对于每个元素,如下所示的内容将是一种享受;不需要 null 检查,因为您永远不会将 null 分配给元素:

                  The reason for these errors is that you're trying to read an array key that doesn't exist. The isset() function is there so you can test for this. Something like the following for each element will work a treat; there's no need for null checks as you never assign null to an element:

                  // check that the 'registered' key exists
                  if (isset($_SESSION['registered'])) {
                  
                      // it does; output the message
                      echo $_SESSION['registered'];
                  
                      // remove the key so we don't keep outputting the message
                      unset($_SESSION['registered']);
                  }
                  

                  你也可以循环使用它:

                  $keys = array('registered', 'badlogin', 'neverused');
                  
                  //iterate over the keys to test
                  foreach($keys as $key) {
                  
                      // test if $key exists in the $_SESSION global array
                      if (isset($_SESSION[$key])) {
                  
                          // it does; output the value
                          echo $_SESSION[$key];
                  
                          // remove the key so we don't keep outputting the message
                          unset($_SESSION[$key]);
                      }
                  }
                  

                  这篇关于PHP 会话的未定义索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                    <tbody id='vXJ1W'></tbody>

                      <i id='vXJ1W'><tr id='vXJ1W'><dt id='vXJ1W'><q id='vXJ1W'><span id='vXJ1W'><b id='vXJ1W'><form id='vXJ1W'><ins id='vXJ1W'></ins><ul id='vXJ1W'></ul><sub id='vXJ1W'></sub></form><legend id='vXJ1W'></legend><bdo id='vXJ1W'><pre id='vXJ1W'><center id='vXJ1W'></center></pre></bdo></b><th id='vXJ1W'></th></span></q></dt></tr></i><div id='vXJ1W'><tfoot id='vXJ1W'></tfoot><dl id='vXJ1W'><fieldset id='vXJ1W'></fieldset></dl></div>
                      <legend id='vXJ1W'><style id='vXJ1W'><dir id='vXJ1W'><q id='vXJ1W'></q></dir></style></legend>

                        1. <small id='vXJ1W'></small><noframes id='vXJ1W'>

                          <tfoot id='vXJ1W'></tfoot>
                            <bdo id='vXJ1W'></bdo><ul id='vXJ1W'></ul>