同一个php文件,在实验室服务器上运行正确,在我自己服务器上出现502错误,但是我将其中的一行代码:  if(empty($node->IP))
改为   :   if(empty($node->IP)&&abc)
(其中abc可换为任意字符串均可)
就神奇的正常运行了,一切功能都正常,求大神指点一二。

解决方案 »

  1.   

    会是这样吗?
    贴出你的测试代码和php版本号
      

  2.   

    我也是测试了半天才找到这个错误之处的。。代码有点长,贴部分吧<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>增加结点</title>
    <link rel="stylesheet" href="css/table_style1.css" type="text/css" />
    <link rel="stylesheet" href="css/fp_style.css" type="text/css" />
    <link rel="stylesheet" href="css/default.css" type="text/css" />
    <link rel="stylesheet" href="css/export.css" type="text/css" />
    <script type="text/javascript" src="./JS/domtab.js"></script>
    <meta http-equiv="Refresh" content="600">
    </head>
    <?php
    include_once("./mysql_conn.php");
    class Node
    {
    public $node_id;
    public $node_name;
    public $IP;
    }
    $nodes = array();//用于存储所有的节点
    $query_node = "SELECT serverID,siteDescription,IPaddress FROM SitesConfig";
    $result_node = mysql_query($query_node) or die("Invalid query: " . mysql_error());
    $nodenum = mysql_num_rows($result_node);
    for($i=0;$i<$nodenum;$i++)
    {
    $nodetemp = new Node();
    $row=mysql_fetch_array($result_node);
    $nodetemp->node_id = $row['serverID'];
    $nodetemp->node_name = $row['siteDescription'];
    $nodetemp->IP = $row['IPaddress'];
    $nodes[] = $nodetemp;
    }

    class Process
    {
    public $pro_cmd;
    public $pro_des;
    }

    if(isset($_POST["join"]))
    {
    $node_id=$_POST["node_id"];
    $node_ip=$_POST["node_ip"];

    if($node_id==-1)
    {
    echo "<script>alert(\"请选择驻地节点\");</script>";
    }
    else if(!preg_match('/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/',$node_ip))
    {
    echo "<script>alert(\"不合法的IP地址!\");</script>";
    }
    else
    {
    $pro_num = trim($_POST["pnum"]);
    //echo $pro_num."<br>";

    $newtable = "ProcessConfig_".$node_id;
    //echo $newtable;
    $pro_query = "show tables like '$newtable'";
    $pro_result = mysql_query($pro_query);
    $tableexits = mysql_num_rows($pro_result);
    $index = 0;
    $tableboolean = true;//用于判断表格建立是否成功或是原表格中数据删除是否成功
    if($tableexits == 0)//假如表格不存在则新建
    {
    $pro_query = "create table $newtable( Id int(11) auto_increment not null primary key, description varchar(255), cmd varchar(255), starttime datetime)";
    $pro_result = mysql_query($pro_query);
    if(!$pro_result)
    {
    echo "<script>alert(\"新建数据表错误!\");</script>";
    $tableboolean = false;
    }

    }
    else//如果表格存在则删除其中原有数据
    {
    $del_query = "DELETE FROM $newtable";
    $del_result = mysql_query($del_query);
    if(!$del_result)
    {
    echo "<script>alert(\"删除原有进程表中信息错误!\");</script>";
    $tableboolean = false;
    }
    }
    if($tableboolean && $pro_num > 0)
    {
    $processes = array();
    for($index=1;$index<=$pro_num;$index++)
    {
    $protemp = new Process();
    $protemp->pro_cmd = trim($_POST["proccmd".$index]);
    $protemp->pro_des = trim($_POST["procdes".$index]);
    $processes[] = $protemp;
    }
    for($index=0;$index<$pro_num;$index++)
    {
    $des = (string)$processes[$index]->pro_des;
    $cmd = (string)$processes[$index]->pro_cmd;
    $pro_query = "INSERT INTO $newtable SET description='$des', cmd='$cmd'";
    $pro_result = mysql_query($pro_query);
    if(!pro_result)
    break;
    }
    if($index<$pro_num)
    echo "<script>alert(\"进程信息插入数据库时发生错误!\");</script>";
    }
    //echo $index;

    $node_port = trim($_POST['node_port']);
    $node_mail = trim($_POST['node_mail']);
    $node_smtp = trim($_POST['node_smtp']);
    $node_mysql_root = trim($_POST['node_mysql_root']);
    $node_mysql_password = trim($_POST['node_mysql_password']);
    $node_log_cycle = trim($_POST['node_log_cycle']);
    $node_cpu_threshold = trim($_POST['node_cpu_threshold']);
    $node_mem_threshold = trim($_POST['node_mem_threshold']);
    $node_disk_threshold = trim($_POST['node_disk_threshold']);
    $node_performance_cycle = trim($_POST['node_performance_cycle']);
    $node_send_cycle = trim($_POST['node_send_cycle']);
    $node_active_cycle = trim($_POST['node_active_cycle']);
    $alarm = $_POST['alarm'];

    $control_ip = trim($_POST['control_ip']);
    $control_port = trim($_POST['control_port']);
    $control_mail = trim($_POST['control_mail']);
    $control_smtp = trim($_POST['control_smtp']);

    $query = "UPDATE SitesConfig SET IPaddress='$node_ip', Port=$node_port, mailAddress='$node_mail', SMTP='$node_smtp', mysqlroot='$node_mysql_root', mysqlpassword='$node_mysql_password', logThreshold=$node_log_cycle, cpuThreshold=$node_cpu_threshold, memoryThreshold=$node_mem_threshold, diskThreshold=$node_disk_threshold, performanceCheckGran=$node_performance_cycle, logSendGran=$node_send_cycle, activeGran=$node_active_cycle, controlIP='$control_ip', controlPort=$control_port, controlMail='$control_mail', controlSMTP='$control_smtp', alarmSwitch=$alarm WHERE serverID = $node_id";
    $update_query = mysql_query($query);
    if(!$update_query)
    echo "<script>alert(\"更新SitesConfig失败!\");window.location='node_join.php';</script>";

    if($tableboolean && $update_query == true && $index == $pro_num)
    {
    echo "<script>alert(\"添加成功\");window.location='node_join.php';</script>";
    }
    else
    {
    echo "<script>alert(\"添加失败\");window.location='node_join.php';</script>";
    //die("Invalid query: " . mysql_error());
    }

    }
    }

    ?>
      

  3.   


    <body>
    <div align="center">
    <!-- start header -->
    <div id="header">
    <table align="center"><tr>
    <td><img style="padding-top:55px" src="image/chairs_logo.png"/></td>
    <td></td>
    <td><img style="padding-top:60px" src="image/1.jpg"/></td>
    </tr></table>
    </div>
    <!-- end header -->
    <?php include('./navigation.php'); ?>
    <!--copy right -->
    <br>
    <div style=" color:#003333; padding-bottom:15px; padding-top:15px"><h3>增加结点</h3></div>
    <div align="center" style="min-height:400px">
    <form name="form1" method="post"  action="node_join.php" >
    <table  class="tablestyle3" width="600"  border="1" cellspacing="0" cellpadding="3" align="center">
    <tr>
    <td class="tdstyle1" width="40%" align="center">驻地结点:
    <select name="node_id" value="-1" style="width:150px">
    <?php
    $output = "<option value=\"-1\" ";
    if($node_id == -1)
    $output .= "selected=\"selected\" ";
    $output .= ">请选择</option>";
    foreach($nodes as $node)
    {
    if(empty($node->IP)&&dffsdfsdff)
    {
    $output .= "<option value=\"".$node->node_id."\" ";
    if($node->node_id == $node_id)
    $output .= "selected=\"selected\" ";
    $output .= ">".$node->node_name."</option>";
    }
    }
    echo $output;
    ?>
    </select>
    </td>

    <td class="tdstyle1" width="40%" align="center">IP地址:&nbsp;<INPUT TYPE="text" name="node_ip" id="node_ip" value="" ></td>

    <td class="tdstyle1" width="20%" align="right">
    <input class="in_style" name="join" id="join" type="submit" onClick="return check_syspara()" value="确认加入">
    </td>
    </tr>
    </table>
    <br >
    <div id="warp">
    <div class="domtab doprevnext"> 
     
    <ul class="domtabs">      <!-- 分页菜单栏 -->
    <li><a href="#tab1">驻地结点配置</a></li> 
    <li><a href="#tab2">总控配置</a></li>
    <li><a href="#tab3">进程配置</a></li>
    </ul>
    <!-- TAB 1 --> 
    <span class="tab">
    <h2><a name="tab1" id="tab1" class="STYLE6" align="center"></a></h2>
    <table class="table_style3" width="800" border="0" cellspacing="0" cellpadding="3">

    <tr>
    <td class="td_style1" width=50% align=right>驻地通信端口:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="node_port" id="node_port" value="4891" />
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>驻地系统管理员邮箱:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="node_mail" id="node_mail" value="" />
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>驻地系统SMTP服务器:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="node_smtp" id="node_smtp" value="" />
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>驻地mysql用户名:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="node_mysql_root" id="node_mysql_root" value="root" />
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>驻地mysql口令:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="node_mysql_password" id="node_mysql_password" value="0000" />
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>日志存档周期:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="node_log_cycle" id="node_log_cycle" value="1" />(单位:天)
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>cpu警报阀值:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="node_cpu_threshold" id="node_cpu_threshold" value="95" />(%)
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>内存警报阀值:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="node_mem_threshold" id="node_mem_threshold" value="95" />(%)
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>硬盘空间警报阀值:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="node_disk_threshold" id="node_disk_threshold" value="90" />(%)
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>性能检测周期:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="node_performance_cycle" id="node_performance_cycle" value="1800" />(单位:秒)
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>日志发送周期:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="node_send_cycle" id="node_send_cycle" value="24" />(单位:小时)
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>活性报告周期:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="node_active_cycle" id="node_active_cycle" value="600" />(单位:秒)
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>警报开关:</td>
    <td class="td_style1" width=50% align=left>
    <select name="alarm" value="1" style="width:150px;">
    <option value="1" >开启</option>
    <option value="0" >关闭</option>
    </select>
    </td>
    </tr>
    </table>
    </span>
    <!-- TAB 2 --> 
    <span class="tab">
    <h2><a name="tab2" id="tab2" class="STYLE6" align="center"></a></h2>
    <table class="table_style3" width="800" border="0" cellspacing="0" cellpadding="3">

    <tr>
    <td class="td_style1" width=50% align=right>总控IP:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="control_ip" id="control_ip" value="211.65.193.125" />
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>总控通信端口:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="control_port" id="control_port" value="4891" />
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>总控邮箱:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="control_mail" id="control_mail" value="[email protected]" />
    </td>
    </tr>
    <tr>
    <td class="td_style1" width=50% align=right>总控SMTP服务器:</td>
    <td class="td_style1" width=50% align=left>
    <input type="text" name="control_smtp" id="control_smtp" value="smtp.njnet.edu.cn" />
    </td>
    </tr>
    </table>
    </span>
    <!--TAB3-->
    <span class="tab">
    <h2><a name="tab3" id="tab3" class="STYLE6" align="center"></a></h2>
    <table  class="tablestyle1" name="proctable" id="proctable" width="500" name="procs" id="procs" align="center" border="2">
    <tr>
    <th width="250px">进程命令行</th>
    <th width="250px">进程描述</th>
    </tr>
    <tr>
    <td align="center"><input class="pro" name="proccmd1" id="proccmd1" value=""/></td>
    <td align="center"><input class="pro" name="procdes1" id="procdes1" value=""/></td>
    </tr>
    <tr>
    <td align="center"><input class="pro" name="proccmd2" id="proccmd2" value=""/></td>
    <td align="center"><input class="pro" name="procdes2" id="procdes2" value=""/></td>
    </tr>
    <tr>
    <td align="center"><input class="pro" name="proccmd3" id="proccmd3" value=""/></td>
    <td align="center"><input class="pro" name="procdes3" id="procdes3" value=""/></td>
    </tr>
    <tr>
    <td align="center"><input class="pro" name="proccmd4" id="proccmd4" value=""/></td>
    <td align="center"><input class="pro" name="procdes4" id="procdes4" value=""/></td>
    </tr>
    <tr>
    <td align="center"><input class="pro" name="proccmd5" id="proccmd5" value=""/></td>
    <td align="center"><input class="pro" name="procdes5" id="procdes5" value=""/></td>
    </tr>
    </table>
    <br>
    <table  class="tablestyle3" width="500"  border="0" cellspacing="0" cellpadding="3" align="center">
    <tr>
    <td align="right">
    <input type="button" name="addprocs" id="addprocs" style="width:100px;height:25px" onClick="changeContent()" value="继续添加进程" />
    </td>
    <tr>
    </table>
    <input type="hidden" name="pnum" id="pnum" value="0" />
    </span>


    </div>
    </div>

    <br>
    </form>
    </div>
    <div style="background-color:#dcdcdc; height:80px; text-align:center; border-top:1px solid; border-top-color:#c4c2c2; margin-top:10px" align="center">
    </div>
    </div>
      

  4.   


    :~$ aptitude show php5
    软件包: php5                    
    状态: 已安装
    自动安装: 否
    版本号: 5.3.10-1ubuntu3.6
    优先级: 可选
    部分: php
    维护者: Ubuntu Developers <[email protected]>
    体系: all
    未压缩尺寸: 21.5 k
    依赖于: libapache2-mod-php5 (>= 5.3.10-1ubuntu3.6) | libapache2-mod-php5filter
               (>= 5.3.10-1ubuntu3.6) | php5-cgi (>= 5.3.10-1ubuntu3.6) | php5-fpm
               (>= 5.3.10-1ubuntu3.6), php5-common (>= 5.3.10-1ubuntu3.6)
      

  5.   

    神奇,把 empty 换一个函数试一下,,  问一下,楼主用的是什么框架呀
      

  6.   

    表示没用框架,empty函数没错呀,我测试过
      

  7.   

    我又几番测试,发现将文件重命名也能正常运行,那就不是php问题了,原来的文件名为node_join.php,有什么玄机?我重命名为node_joinn.php也行呀,真心纠结