duanmi8349 2011-07-01 17:33
浏览 39
已采纳

为什么这个脚本不能正确清理输出?

I am trying to sanitize the output of what should be a simple email script, but it only outputs a blank page. Here is the script:

    <?php
define("EMAIL", "info@silentpost.net");

if(isset($_POST['submit'])) {

  //include validation class
  include('./support/validate.class.php');

  //assign post data to variables
  $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
  $_POST['email'] = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
  $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);

  $name = trim($_POST['name']);
  $email = trim($_POST['email']);
  $message = trim($_POST['message']);

  //start validating our form
  $v = new validate();
  $v->validateStr($name, "name", 3, 75);
  $v->validateEmail($email, "email");
  $v->validateStr($message, "message", 5, 1000);

  if(!$v->hasErrors()) {
        $header = "From: $email
" . "Reply-To: $email
";
        $subject = "email from silentpost.net website!";
        $email_to = EMAIL;

        $emailMessage = "Name: " . $name . "
";
        $emailMessage .= "Email: " . $email . "

";
        $emailMessage .= $message;

        @mail($email_to, $subject ,$emailMessage ,$header );

    } else {
    //set the number of errors message
    $message_text = $v->errorNumMessage();

    //store the errors list in a variable
    $errors = $v->displayErrors();

    //get the individual error messages
    $nameErr = $v->getError("name");
    $emailErr = $v->getError("email");
    $messageErr = $v->getError("message");
  }//end error check


}// end isset
?>

If I omit the following code, the script will run fine:

$_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$_POST['email'] = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);

if necessary, I will include the class, but I don't think it is an issue with the class, as removing the filter_var lines outputs correctly.

Any help would be appreciated.

  • 写回答

2条回答 默认 最新

  • doujing5726 2011-07-01 17:38
    关注

    I would do two things:

    A. Make sure you're running PHP >= 5.2 (minimum for the filter_var function).

    B. Add error_reporting(E_ALL); to the top of the script, this will let you see what error is being thrown causing the blank page.

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

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮