2

我不确定为什么这不起作用,但我想在下面的代码中说的是,如果用户未登录if ((!isset($username)) && (!isset($userid))){,则查看其他表单(如果他们已登录),然后显示消息说明他们必须注销查看页面。

问题是即使用户登录,它仍然显示表单而不是消息。

下面是代码:

        <?php
ini_set('display_errors',1); 
 error_reporting(E_ALL);
        session_start();

        include('member.php');

  $user = (isset($_POST['user'])) ? $_POST['user'] : '';
  $email = (isset($_POST['email'])) ? $_POST['email'] : '';

        if ((!isset($username)) && (!isset($userid))){

            echo "<form action='./forgotpass.php' method='post'>
            <table>
            <tr>
            <td></td>
            <td id='errormsg'>$errormsg</td>
            </tr>
            <tr>
            <td>Username</td>
            <td><input type='text' name='user' /></td>
            </tr>
            <tr>
            <td>Email</td>
            <td><input type='text' name='email' /></td>
            </tr>
            <tr>
            <td></td>
            <td><input type='submit' name='resetbtn' value='Reset Password' /></td>
            </tr>
            </table>
            </form>";

        }
        else
        {
        echo "Please Logout to view this Page.";    
        }
        ?>

在上面的代码中,我包含了 member.php 页面,我不知道这是否有很大的不同,但 member.php 页面的代码如下:

<?php

if (isset($_SESSION['teacherforename'])) {

$_SESSION['teacherforename'] = $_SESSION['teacherforename'];

}

if (isset($_SESSION['teachersurname'])) {

$_SESSION['teachersurname'] = $_SESSION['teachersurname'];

}

if (isset($_SESSION['teacherid'])) {

      $userid = $_SESSION['teacherid'];

  }

if (isset($_SESSION['teacherusername'])) {

      $username = $_SESSION['teacherusername'];

  }

        ?>
4

3 回答 3

1

检查它是否已设置并且它是否有任何值。

if ( (!isset($username) && empty($username)) && (!isset($userid) && empty($userid)) ){ 
于 2012-10-09T17:58:57.793 回答
1

检查这个你试过

<?php    
$user = (isset($_POST['user'])) ? $_POST['user'] : '';
  $email = (isset($_POST['email'])) ? $_POST['email'] : '';

        if ((!isset($username)) && (!isset($userid))){
       echo 'empty set';
}

以上将输出空集,这意味着 $user 和 $email 已设置

为了使它正确也使用empty()

正确一个

$user = (isset($_POST['user'])) ? $_POST['user'] : '';
  $email = (isset($_POST['email'])) ? $_POST['email'] : '';

        if ((!isset($username)) && !empty($username) &&  (!isset($userid) && !empty($email ))){
       echo 'empty set';
}
于 2012-10-09T18:03:02.737 回答
0
$user = (isset($_POST['user'])) ? $_POST['user'] : NULL;
$email = (isset($_POST['email'])) ? $_POST['email'] : NULL;

我相信将变量设置为 '' 将返回 trueisset()

伊塞特() Returns TRUE if var exists and has value other than NULL, FALSE otherwise.

于 2012-10-09T17:56:03.490 回答