包含文件时发生冲突


Conflict in including of a file

我试图包含一个文件,该文件生成2个需要添加的随机数,或者我们称之为captcha。我有两个登录:一个需要员工id、出生日期和captcha答案(我称之为简单登录)。而另一个需要你的名字、姓氏、出生日期和captcha(我称之为标准登录)。因此,我有两个单选按钮供用户选择是简单登录还是标准登录。所以我遇到了这个问题,当你选择登录时,你需要回答captcha(captcha发送会话来获取答案),所以现在发生的事情是,简单登录中的captcha总是被标准登录中的captcha覆盖。我想我会做的是设置一个条件,如果选择了单选按钮(轻松登录),那么这就是它将被包括在内的时间。但我不知道该怎么做。

这是captcha代码:captcha.php

<?php
session_start();
$n1=rand(1,6); //Generate First number between 1 and 6  
$n2=rand(5,9); //Generate Second number between 5 and 9  
$answer=$n1+$n2;  
$math = "What is ".$n1." + ".$n2." ? ";  
$_SESSION['vercode'] = $answer;
print $math;
?>

下面是我的界面代码:

index.php

<SCRIPT TYPE="text/javascript">
function toggleTables(which)
{
if(which == "0") {
    document.getElementById('standard').style.display = "table";
    document.getElementById('customize').style.display = "none";
    }
    if(which == "1") {
    document.getElementById('customize').style.display = "table";
    document.getElementById('standard').style.display = "none";
    }
}
</SCRIPT>
</head>
<body style="background: url(../images/background.jpg) no-repeat center center fixed; 
          -webkit-background-size: cover;
          -moz-background-size: cover;
          -o-background-size: cover;
          background-size: cover;" >
<a href="http://i-refer.elitebpocareers.com" align="center"><?php include('../include/logoheader.php'); ?></a>


<div class="row">
<div class="twelve columns">
    <hr />
</div>
</div>
<div class="row">
<div class="two columns">
</div>
<div class="eight columns">
    <div class="content">
        <?php include('../include/retain-empid.php'); ?>
        <br>
        <input name="radio" type="radio" id="customize_1" onClick="toggleTables('0')" value="radio" /><font color="white">Standard Login</font>
        <input name="radio" type="radio" id="customize_0" onClick="toggleTables('1')" value="radio" checked="checked"/><font color="white">Easy Login</font>
        <form name="loginform" action="login_exec.php" method="post" >
        <center><?php include('../function/login_errmsg.php'); ?></center>

        <table width="100%" class="imagetable" cellpadding="0" cellspacing="0" id="customize">
                <tr>
                <th colspan="4">
                    Easy Log-in For Registered Convergys Employees
                </th>
            </tr>
                <tr>
                    <td align="right">
                        <label>Employee Number</label>
                    </td>
                    <td>
                    <input type="text" placeholder="Employee Number" name="txt_EmpID" autoComplete="off" value=<?php echo $value; ?> >
                    </td>
                <td align="right">
                        <label>Birthday</label>
                    </td>

                <td>
                    <input type="date" class="" placeholder="Birthday" id="txt_BDate" name="txt_BDate" autoComplete="off" maxlength = "10" 
                    style ="width:170px;"/>
                </td>
                </tr>
            <tr>
                <td align="right">
                    <label class="labels" align="center">
                        <strong>
                        </strong>   
                    </label>
                    </td>
                <td>
                <?php
                include ('../include/mathcaptcha.php');
                ?>
                </td>
                <td>
                    <input name="captcha" type="text" placeholder="Answer to math question">
                </td>
                <td>
                </td>
                <td>
                    <input type="submit" id="submit" name="btn_refer" class="btn" value="Submit" 
                    style=" width: 170px; height: 30px; font-size: 11pt; ">
                    </td>
                </tr>
        </table>
        </form>
        <form action="otherlogin_exec.php" method="post"> 
        <table width="100%" class="imagetable" cellpadding="0" cellspacing="0" id="standard" style="display: none">
                <tr>
                    <th colspan="4">
                        Standard Log-in For All Registered Users
                    </th>
                </tr>
            <tr>
                <td align = "right">
                    <label>First name:</label>
                </td>
                <td>
                    <input type="text" placeholder="First Name" name="txtFirstName" autoComplete="off" >
                </td>
                <td>
                    <label>Last name:</label>
                </td>
                <td>
                    <input type="text" placeholder="Last Name" name="txtLastName" autoComplete="off" >
                </td>
                </tr>
            <tr>
                <td>
                    <label>Birthday:</label>
                </td>
                    <td>
                    <input type="date" class="" placeholder="Birthday" id="txt_BDate" 
                    name="txtPassword" autoComplete="off" maxlength = "10" style = "width:170px;"/>
                </td>
                <td>
                    <label class="labels" align="center">
                        <strong>
                        </strong>   
                    </label>
                </td>
                <td>
                <?php
                include ('../include/mathcaptcha.php');
                ?>
                </td>                   
                <td>
                    <input name="captcha" type="text" placeholder="Answer to math question">
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                    <input type="submit" id="submit" name="btn_refer" class="btn" value="Submit" 
                    style=" width: 100%; height: 30px; font-size: 11pt; ">
                </td>
            </tr>
        </table>
        </form>
    </div>
    </div>

将文件的第一行设置为

<?php include_once ('../include/mathcaptcha.php'); ?>

然后更改的线路

      <td>
            <?php
            include ('../include/mathcaptcha.php');
            ?>
            </td>       

      <td><?php echo $math;?></td>

并从captcha文件中取出打印件。PHP不会影响页面的设计,只会影响输出的数据,这些数据应该根据需要进行更改。