dqsw7529 2012-09-03 18:57
浏览 26
已采纳

首字母大写和剥离html代码

I have the following html page: What I am looking to do is capitalize the first letter (which is working without any issue) and strip the textbox of any html code or any code that has a combincation of "<" "/>" ">" so user cannot insert malicious code to execute at server end.

I found a code which strips:

var StrippedString = OriginalString.replace(/(<([^>]+)>)/ig,"");

How do I add the above code to the below page so it takes care of both?

<?php
/**
 * ****************************************************************************
 * Micro Protector
 * 
 * Version: 1.0
 * Release date: 2007-09-10
 * 
 * USAGE:
 *   Define your requested password below and inset the following code
 *   at the beginning of your page:
 *   <?php require_once("microProtector.php"); ?>
 * 
 *  
 * 
 ******************************************************************************/


$Password = 'TESTPASS'; // Set your password here



/******************************************************************************/
   if (isset($_POST['submit_pwd'])){
      $pass = isset($_POST['passwd']) ? $_POST['passwd'] : '';

      if ($pass != $Password) {
         showForm("Wrong password");
         exit();     
      }
   } else {
      showForm();
      exit();
   }

function showForm($error="LOGIN"){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
   <title>IMC - Authentication</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
<Script>
<!--
function capitalize(form) {
    value = form.value;
    newValue = '';
    value = value.split(' ');
    for(var i = 0; i < value.length; i++) {
        newValue += value[i].substring(0,1).toUpperCase() +
        value[i].substring(1,value[i].length) + '';
    }
form.value = newValue;
}
-->
</Script>
</head>
<body>
<center><a href="http://www.test.com"><img src="test.png" border=0 /></a></center>
<br><br><br>
    <div id="main">
      <div class="caption"><?php echo $error; ?></div>
      <div id="icon">&nbsp;</div>
      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="pwd">
    Your Name:
        <table>
          <tr><td><input class="text" name="name" onBlur="capitalize(this);" maxlength=12 type="text" /></td></tr>
        </table> 
        Password:
        <table>
          <tr><td><input class="text" name="passwd" maxlength=8 type="password" /></td></tr>
          <tr><td align="center"><br/>
             <input class="text" type="submit" name="submit_pwd" value="Login" />
          </td></tr>
        </table>  
      </form>
   </div>
</body>
</html>

<?php   
}
?>
  • 写回答

2条回答 默认 最新

  • dpwdldgn43486 2012-09-03 19:00
    关注

    Add newValue = newValue.replace(/(<([^>]+)>)/ig,""); before form.value = newValue;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题