标头已发送...哪里? [复制]

2024-03-06

有人知道如何在此脚本中发送标头吗?我正在使用此脚本来验证表单。因此,它导致发送标头,因此当我在实现此脚本后尝试引导用户时,它会导致正常的“警告:无法修改标头信息 - 标头已发送”消息。这是脚本:

<?php
class ValidatorObj
{
    var $variable_name;
    var $validator_string;
 var $error_string;
} 

/**
* Base class for custom validation objects
**/
 class CustomValidator 
 {
    function DoValidate(&$formars,&$error_hash)
{
    return true;
}
}

/** Default error messages*/
define("E_VAL_REQUIRED_VALUE","Please enter the value for %s");
define("E_VAL_MAXLEN_EXCEEDED","Maximum length exceeded for %s.");
define("E_VAL_MINLEN_CHECK_FAILED","Please enter input with length more than %d for %s");
define("E_VAL_ALNUM_CHECK_FAILED","Please provide an alpha-numeric input for %s");
define("E_VAL_ALNUM_S_CHECK_FAILED","Please provide an alpha-numeric input for %s");
define("E_VAL_NUM_CHECK_FAILED","Please provide numeric input for %s");
define("E_VAL_ALPHA_CHECK_FAILED","Please provide alphabetic input for %s");
define("E_VAL_ALPHA_S_CHECK_FAILED","Please provide alphabetic input for %s");
define("E_VAL_EMAIL_CHECK_FAILED","Please provide a valida email address");
define("E_VAL_LESSTHAN_CHECK_FAILED","Enter a value less than %f for %s");
define("E_VAL_GREATERTHAN_CHECK_FAILED","Enter a value greater than %f for %s");
define("E_VAL_REGEXP_CHECK_FAILED","Please provide a valid input for %s");
define("E_VAL_DONTSEL_CHECK_FAILED","Wrong option selected for %s");
define("E_VAL_SELMIN_CHECK_FAILED","Please select minimum %d options for %s");
define("E_VAL_SELONE_CHECK_FAILED","Please select an option for %s");
define("E_VAL_EQELMNT_CHECK_FAILED","Value of %s should be same as that of %s");
define("E_VAL_NEELMNT_CHECK_FAILED","Value of %s should not be same as that of %s");

class FormValidator 
{
    var $validator_array;
    var $error_hash;
    var $custom_validators;

function FormValidator()
{
    $this->validator_array = array();
    $this->error_hash = array();
    $this->custom_validators=array();
}

function AddCustomValidator(&$customv)
{
    array_push($this->custom_validators,$customv);
}

function addValidation($variable,$validator,$error)
{
    $validator_obj = new ValidatorObj();
    $validator_obj->variable_name = $variable;
    $validator_obj->validator_string = $validator;
    $validator_obj->error_string = $error;
    array_push($this->validator_array,$validator_obj);
}
function GetErrors()
{
    return $this->error_hash;
}

function ValidateForm()
{
    $bret = true;

    $error_string="";
    $error_to_display = "";


    if(strcmp($_SERVER['REQUEST_METHOD'],'POST')==0)
    {
        $form_variables = $_POST;
    }
    else
    {
        $form_variables = $_GET;
    }

    $vcount = count($this->validator_array);


    foreach($this->validator_array as $val_obj)
    {
        if(!$this->ValidateObject($val_obj,$form_variables,$error_string))
        {
            $bret = false;
            $this->error_hash[$val_obj->variable_name] = $error_string;
        }
    }

    if(true == $bret && count($this->custom_validators) > 0)
    {
        foreach( $this->custom_validators as $custom_val)
        {
            if(false == $custom_val->DoValidate($form_variables,$this->error_hash))
            {
                $bret = false;
            }
        }
    }
    return $bret;
}


function ValidateObject($validatorobj,$formvariables,&$error_string)
{
    $bret = true;

    $splitted = explode("=",$validatorobj->validator_string);
    $command = $splitted[0];
    $command_value = '';

    if(isset($splitted[1]) && strlen($splitted[1])>0)
    {
        $command_value = $splitted[1];
    }

    $default_error_message="";

    $input_value ="";

    if(isset($formvariables[$validatorobj->variable_name]))
    {
     $input_value = $formvariables[$validatorobj->variable_name];
    }

    $bret = $this->ValidateCommand($command,$command_value,$input_value,
                                $default_error_message,
                                $validatorobj->variable_name,
                                $formvariables);


    if(false == $bret)
    {
        if(isset($validatorobj->error_string) &&
            strlen($validatorobj->error_string)>0)
        {
            $error_string = $validatorobj->error_string;
        }
        else
        {
            $error_string = $default_error_message;
        }

    }//if
    return $bret;
}

function validate_req($input_value, &$default_error_message,$variable_name)
{
  $bret = true;
    if(!isset($input_value) ||
        strlen($input_value) <=0)
    {
        $bret=false;
        $default_error_message = sprintf(E_VAL_REQUIRED_VALUE,$variable_name);
    }   
  return $bret; 
}

function validate_maxlen($input_value,$max_len,$variable_name,&$default_error_message)
{
    $bret = true;
    if(isset($input_value) )
    {
        $input_length = strlen($input_value);
        if($input_length > $max_len)
        {
            $bret=false;
            $default_error_message = sprintf(E_VAL_MAXLEN_EXCEEDED,$variable_name);
        }
    }
    return $bret;
}

function validate_minlen($input_value,$min_len,$variable_name,&$default_error_message)
{
    $bret = true;
    if(isset($input_value) )
    {
        $input_length = strlen($input_value);
        if($input_length < $min_len)
        {
            $bret=false;
            $default_error_message = sprintf(E_VAL_MINLEN_CHECK_FAILED,$min_len,$variable_name);
        }
    }
    return $bret;
}

function test_datatype($input_value,$reg_exp)
{
    if(ereg($reg_exp,$input_value))
    {
        return false;
    }
    return true;
}

function validate_email($email) 
{
    return eregi("^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$", $email);
}

function validate_for_numeric_input($input_value,&$validation_success)
{

    $more_validations=true;
    $validation_success = true;
    if(strlen($input_value)>0)
    {

        if(false == is_numeric($input_value))
        {
            $validation_success = false;
            $more_validations=false;
        }
    }
    else
    {
        $more_validations=false;
    }
    return $more_validations;
}

function validate_lessthan($command_value,$input_value,
            $variable_name,&$default_error_message)
{
    $bret = true;
    if(false == $this->validate_for_numeric_input($input_value,
                                $bret))
    {
        return $bret;
    }
    if($bret)
    {
        $lessthan = doubleval($command_value);
        $float_inputval = doubleval($input_value);
        if($float_inputval >= $lessthan)
        {
            $default_error_message = sprintf(E_VAL_LESSTHAN_CHECK_FAILED,
                                    $lessthan,
                                    $variable_name);
            $bret = false;
        }//if
    }
    return $bret ;
}

function validate_greaterthan($command_value,$input_value,$variable_name,&$default_error_message)
{
    $bret = true;
    if(false == $this->validate_for_numeric_input($input_value,$bret))
    {
        return $bret;
    }
    if($bret)
    {
        $greaterthan = doubleval($command_value);
        $float_inputval = doubleval($input_value);
        if($float_inputval <= $greaterthan)
        {
            $default_error_message = sprintf(E_VAL_GREATERTHAN_CHECK_FAILED,
                                    $greaterthan,
                                    $variable_name);
            $bret = false;
        }//if
    }
    return $bret ;
}

function validate_select($input_value,$command_value,&$default_error_message,$variable_name)
{
    $bret=false;
    if(is_array($input_value))
    {
        foreach($input_value as $value)
        {
            if($value == $command_value)
            {
                $bret=true;
                break;
            }
        }
    }
    else
    {
        if($command_value == $input_value)
        {
            $bret=true;
        }
    }
    if(false == $bret)
    {
        $default_error_message = sprintf(E_VAL_SHOULD_SEL_CHECK_FAILED,
                                        $command_value,$variable_name);
    }
    return $bret;
}

function validate_dontselect($input_value,$command_value,&$default_error_message,$variable_name)
{
   $bret=true;
    if(is_array($input_value))
    {
        foreach($input_value as $value)
        {
            if($value == $command_value)
            {
                $bret=false;
                $default_error_message = sprintf(E_VAL_DONTSEL_CHECK_FAILED,$variable_name);
                break;
            }
        }
    }
    else
    {
        if($command_value == $input_value)
        {
            $bret=false;
            $default_error_message = sprintf(E_VAL_DONTSEL_CHECK_FAILED,$variable_name);
        }
    }
  return $bret;
}



function ValidateCommand($command,$command_value,$input_value,&$default_error_message,$variable_name,$formvariables)
{
    $bret=true;
    switch($command)
    {
        case 'req':
                    {
                        $bret = $this->validate_req($input_value, $default_error_message,$variable_name);
                        break;
                    }

        case 'maxlen':
                    {
                        $max_len = intval($command_value);
                        $bret = $this->validate_maxlen($input_value,$max_len,$variable_name,
                                            $default_error_message);
                        break;
                    }

        case 'minlen':
                    {
                        $min_len = intval($command_value);
                        $bret = $this->validate_minlen($input_value,$min_len,$variable_name,
                                        $default_error_message);
                        break;
                    }

        case 'alnum':
                    {
                        $bret= $this->test_datatype($input_value,"[^A-Za-z0-9]");
                        if(false == $bret)
                        {
                            $default_error_message = sprintf(E_VAL_ALNUM_CHECK_FAILED,$variable_name);
                        }
                        break;
                    }

        case 'alnum_s':
                    {
                        $bret= $this->test_datatype($input_value,"[^A-Za-z0-9 ]");
                        if(false == $bret)
                        {
                            $default_error_message = sprintf(E_VAL_ALNUM_S_CHECK_FAILED,$variable_name);
                        }
                        break;
                    }

        case 'num':
        case 'numeric':
                    {
                        $bret= $this->test_datatype($input_value,"[^0-9]");
                        if(false == $bret)
                        {
                            $default_error_message = sprintf(E_VAL_NUM_CHECK_FAILED,$variable_name);
                        }
                        break;                          
                    }

        case 'alpha':
                    {
                        $bret= $this->test_datatype($input_value,"[^A-Za-z]");
                        if(false == $bret)
                        {
                            $default_error_message = sprintf(E_VAL_ALPHA_CHECK_FAILED,$variable_name);
                        }
                        break;
                    }
        case 'alpha_s':
                    {
                        $bret= $this->test_datatype($input_value,"[^A-Za-z ]");
                        if(false == $bret)
                        {
                            $default_error_message = sprintf(E_VAL_ALPHA_S_CHECK_FAILED,$variable_name);
                        }
                        break;
                    }
        case 'email':
                    {
                        if(isset($input_value) && strlen($input_value)>0)
                        {
                            $bret= $this->validate_email($input_value);
                            if(false == $bret)
                            {
                                $default_error_message = E_VAL_EMAIL_CHECK_FAILED;
                            }
                        }
                        break;
                    }
        case "lt": 
        case "lessthan": 
                    {
                        $bret = $this->validate_lessthan($command_value,
                                                $input_value,
                                                $variable_name,
                                                $default_error_message);
                        break;
                    }
        case "gt": 
        case "greaterthan": 
                    {
                        $bret = $this->validate_greaterthan($command_value,
                                                $input_value,
                                                $variable_name,
                                                $default_error_message);
                        break;
                    }

        case "regexp":
                    {
                        if(isset($input_value) && strlen($input_value)>0)
                        {
                            if(!preg_match("$command_value",$input_value))
                            {
                                $bret=false;
                                $default_error_message = sprintf(E_VAL_REGEXP_CHECK_FAILED,$variable_name);
                            }
                        }
                        break;
                    }
      case "dontselect": 
      case "dontselectchk":
      case "dontselectradio":
                    {
                        $bret = $this->validate_dontselect($input_value,
                                                           $command_value,
                                                           $default_error_message,
                                                            $variable_name);
                         break;
                    }//case

      case "shouldselchk":
      case "selectradio":
                  {
                        $bret = $this->validate_select($input_value,
                               $command_value,
                               $default_error_message,
                                $variable_name);
                        break;
                  }//case
      case "selmin":
                    {
                        $min_count = intval($command_value);

                        if(isset($input_value))
                        {
                            if($min_count > 1)
                            {
                                $bret = (count($input_value) >= $min_count )?true:false;
                            }
                            else
                            {
                              $bret = true;
                            }
                        }
                        else
                        {
                            $bret= false;
                            $default_error_message = sprintf(E_VAL_SELMIN_CHECK_FAILED,$min_count,$variable_name);
                        }

                        break;
                    }//case
     case "selone":
                    {
                        if(false == isset($input_value)||
                            strlen($input_value)<=0)
                        {
                            $bret= false;
                            $default_error_message = sprintf(E_VAL_SELONE_CHECK_FAILED,$variable_name);
                        }
                        break;
                    }
     case "eqelmnt":
                    {

                        if(isset($formvariables[$command_value]) &&
                           strcmp($input_value,$formvariables[$command_value])==0 )
                        {
                            $bret=true;
                        }
                        else
                        {
                            $bret= false;
                            $default_error_message = sprintf(E_VAL_EQELMNT_CHECK_FAILED,$variable_name,$command_value);
                        }
                    break;
                    }
      case "neelmnt":
                    {
                        if(isset($formvariables[$command_value]) &&
                           strcmp($input_value,$formvariables[$command_value]) !=0 )
                        {
                            $bret=true;
                        }
                        else
                        {
                            $bret= false;
                            $default_error_message = sprintf(E_VAL_NEELMNT_CHECK_FAILED,$variable_name,$command_value);
                        }
                        break;
                    }
    }//switch
    return $bret;
}//validdate command
}?> 

之后}?>

if you select all (Ctrl+A) you will see the white space proceeding the ?>

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

标头已发送...哪里? [复制] 的相关文章

  • 将二进制数据从 C# 上传到 PHP

    我想将文件从 Windows C 应用程序上传到运行 PHP 的 Web 服务器 我知道 WebClient UploadFile 方法 但我希望能够分块上传文件 以便我可以监控进度并能够暂停 恢复 因此 我正在读取文件的一部分并使用 We
  • shell_exec 的输出被截断为 100 个字符

    当在 shell 中运行以下命令时 curl F file filename http 192 168 0 1 产生以下输出 Accuracy 0 0 1 classification Accuracy 0 0 1 classificati
  • 从关系中合并 Laravel 中的集合

    假设我有 3 张桌子 Images Subject Style 关系是多对多 图像 主题 和多对多 图像 样式 现在我想做一些类似的事情 result subjectResult gt images gt merge styleResult
  • Monolog,如何将 PHP 数组记录到控制台?

    我正在使用浏览器处理程序将消息记录到 JS 控制台 require once vendor autoload php use Monolog Logger use Monolog Handler BrowserConsoleHandler
  • 合并 csv 文件 [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 如何在 PHP 或 joomla 中将多个 CSV 文件合并为一个 csv 文件 将文件夹中 csv 文件中的所有数据合并到文本文件中 通
  • 一些基本的 PHP 问题 [已关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我只是有一些基本的 php 问题来加深我对学习的理解 但我找不到简单的答案 我有一个 php ajax 应用程序 它生成 mysql
  • curl 无法获取网页内容,为什么?

    我正在使用curl 脚本转到链接并获取其内容以进行进一步操作 以下是链接和curl脚本
  • 如何使用 PHP 从内容中查找 URL?

    需要一个简单的 preg match 它将在内容中查找 c aspx 不带引号 如果找到 它将返回整个 url 举个例子 content div 4 a href m c aspx mt 01 9310ba801f1255e02e411d8
  • 有没有办法在不使用 foreach 或其他函数的情况下在 PHP 中内爆关联数组的键和值?

    我有一个像这样的关联数组 myarray array a gt 1 b gt 2 c gt 3 我想显示数组键和值 如下所示 a is 1 b is 2 c is 3 我不想使用 print r 或 var dump 来执行此操作 我也不想
  • PHP语言问题

    我有一个 php 页面 它将邮件发送到特定电子邮件 其中包含此页面表单中的数据 邮件必须以网站的母语 阿拉伯语 发送 但是当我单击表单上的提交按钮时 收到的邮件一半可读 阿拉伯语 另一部分不可读 符号 我想知道如何解决这个问题并且能够发送邮
  • 如何将 .env 添加到 codeigniter?

    我尝试按照以下步骤使 php 连接到 Outlookhttps learn microsoft com en us outlook rest php tutorial https learn microsoft com en us outl
  • HTTP_REFERER 返回 NULL,$_SERVER 中不存在密钥

    使用以来第一次 SERVER HTTP REFERER 它给了我NULL因此 当我做var dump SERVER the HTTP REFERER密钥不存在 我还尝试使用不同的浏览器和不同的网站访问网站 但没有结果 该网站在基于 Linu
  • Laravel 5.6 - 注册表无法正常工作并且不显示任何错误

    在我最近的一个项目中 定制登记表不管用 当我单击注册按钮时 它会重新加载注册表单 不会打印任何错误 并且不会将数据插入数据库中 这是注册表的外观 这里是移民文件代码 public function up Schema create user
  • 在 Laravel 中按数据透视表 create_at 排序

    在我的数据库中 我有以下表格 courses id 名称 创建时间 更新时间 students id 名称 创建时间 更新时间 课程 学生 id course id student id created at updated at 我正在尝
  • PHP OOP 静态属性语法错误 [关闭]

    这个问题不太可能对任何未来的访客有帮助 它只与一个较小的地理区域 一个特定的时间点或一个非常狭窄的情况相关 通常不适用于全世界的互联网受众 为了帮助使这个问题更广泛地适用 访问帮助中心 help reopen questions 为什么不
  • 将单独的月、日和年值转换为时间戳

    我有月份值 1 12 日期值 1 31 和年份值 2010 2011 2012 我还有一个小时值和一个分钟值 我怎样才能把这个给strtotime 它可以以某种方式将其转换为时间戳吗 当您已经知道年月和日期时 为什么将字符串转换为日期 us
  • 如何从列表创建多维数组?

    我在 MySQL 中有一个带有父 ID 的类别列表 如何从列表中创建 PHP 数组 ID Category Parent ID 1 Car NULL 2 Education NULL 3 Mathematics 2 4 Physics 2
  • 打印表数据mysql php

    我在尝试打印表格的一些数据时遇到问题 我是 php mysql 的新手 但我认为我的代码是正确的 这里是 h1 Lista de usu rios h1
  • PHPunit - 错误

    当 PHPunit 框架不希望发生的错误发生时 测试会停止 PHP 会抛出错误 但 PHPunit 不会记录这是一个错误 我如何确保 PHPunit 将其记录为错误 免责声明 我是 PHPUnit 的新手 我也试图弄清楚 发生错误时会发生什
  • 使用 md5 加密的 PHP 和 Mysql 查询出现问题

    我使用普通的 php mysql 插入查询并使用 md5 加密密码 这是插入查询 sql mysql query INSERT INTO user username password role approved values usernam

随机推荐