导航:首页 > 编程语言 > php表单提交前验证

php表单提交前验证

发布时间:2022-09-14 21:44:17

php验证码怎么在前from表单验证呢请大师请教,谢谢

  1. 把验证码的值当作一个参数存在html表单/ajax表单中(如,以vcode命名增加一个hiden text);

  2. 在控制器接收表单的逻辑,接收$_POST['vcode'],判断$_POST['vcode']是不是生成的验证码,是,跳过,不是返回验证码错误到表单页面;

  3. 其实验证就类似接口一样,双方约定规则,统一密钥,而验证只是你自己去验证罢了

㈡ php表单提交到邮箱怎么做到

index.php
<?php
$stm="邮件内容";
require("smtp.php");
##########################################
$smtpserver = "mail.chg168.com";//SMTP服务器
$smtpserverport = 25;//SMTP服务器端口
$smtpusermail = "[email protected]";//SMTP服务器的用户邮箱
$smtpemailto = "[email protected]";//发送给谁
$smtpuser = "[email protected]";//SMTP服务器的用户帐号
$smtppass = "111111";//SMTP服务器的用户密码
$mailsubject = "dddddddddddd ";//邮件主题
$mailbody = $stm;//邮件内容
$mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件
##########################################
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
$smtp->debug = TRUE;//是否显示发送的调试信息
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
echo "<script>alert('邮件发送成功');parent.document.ADDUser.cheheh.click();</script>";
exit;
}
?>

smtp.php
<?php
class smtp
{
/* Public Variables */
var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;

/* Private Variables */
var $sock;

/* Constractor */
function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
$this->host_name = "localhost"; //is used in HELO command
$this->log_file = "";
$this->sock = FALSE;
}

/* Main Function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);
$header .= "MIME-Version:1.0\r\n";
if($mailtype=="HTML")
{
$header .= "Content-Type:text/html\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "")
{
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->strip_comment($to));

if ($cc != "")
{
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}
if ($bcc != "")
{
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}
$sent = TRUE;
foreach ($TO as $rcpt_to)
{
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to))
{
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body))
{
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
}
else
{
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remote host\n");
}
return $sent;
}

/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo))
{
return $this->smtp_error("sending HELO command");
}

#auth
if($this->auth)
{
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user)))
{
return $this->smtp_error("sending HELO command");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass)))
{
return $this->smtp_error("sending HELO command");
}
}
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">"))
{
return $this->smtp_error("sending MAIL FROM command");
}
if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">"))
{
return $this->smtp_error("sending RCPT TO command");
}
if (!$this->smtp_putcmd("DATA"))
{
return $this->smtp_error("sending DATA command");
}
if (!$this->smtp_message($header, $body))
{
return $this->smtp_error("sending message");
}
if (!$this->smtp_eom())
{
return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
}
if (!$this->smtp_putcmd("QUIT"))
{
return $this->smtp_error("sending QUIT command");
}
return TRUE;
}

function smtp_sockopen($address)
{
if ($this->relay_host == "")
{
return $this->smtp_sockopen_mx($address);
}
else
{
return $this->smtp_sockopen_relay();
}
}

function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok()))
{
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}
$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;;
}

function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);
if (!@getmxrr($domain, $MXHOSTS))
{
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host)
{
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok()))
{
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}
$this->log_write("Connected to mx host ".$host."\n");
return TRUE;
}
$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}

function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
return TRUE;
}

function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");
return $this->smtp_ok();
}

function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response."\n");
if (!ereg("^[23]", $response))
{
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}

function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "")
{
if($cmd=="")
{
$cmd = $arg;
}
else
{
$cmd = $cmd." ".$arg;
}
}
fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");
return $this->smtp_ok();
}

function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}

function log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "")
{
return TRUE;
}
$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a")))
{
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}

function strip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address))
{
$address = ereg_replace($comment, "", $address);
}
return $address;
}

function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);
return $address;
}

function smtp_debug($message)
{
if ($this->debug)
{
//echo $message;
}
}
}
?>

我测试过的哈 自己的网站也是用的这个 绝对没有问题哈,你可以入群29077119 里面有这方面的高手哈

㈢ PHP传值查询SQL,onclick怎么提交之前验证表单

<script>
func=function(){
txt=document.getElementById("txt").value;

if((/(^(1)[3|15|16|18]{1})([0-9]{1})(d{8}$)/.test(txt))){this.form1.submit();}
else
{alert("电话格式不对!");}
}
</script>
<body>
<div>
<formname="form1">
<inputtype="text"name="txt"id="txt"/>
<inputtype="button"value="submit"onclick="func()"/>
</form>
</div>希望能帮到你

㈣ php form提交账户密码 怎么写验证

你是要验证账户名和密码?如果是验证账户名和密码,当客户点击登录按钮的时候,你将你的客户输入的信息post请求到你这后台的php上,然后先在数据库查找对应的用户名,用户名查到之后,然后比对相应用户名的密码是否正确。正确之后,就完成了验证,否则给客户错误提示。

㈤ php 表单怎么验证提交的数据

<input name=wd type=text id=kw size=42 style="height:26px" maxlength=100>
</p>
<DIV class=hwr_hidden id=hwr_div onclick=stopClosePen(event)></DIV>
<p style="text-align: center">
<input type=submit onClick="return goto();" value=<?php echo $config["name"];?> id=su> <INPUT id=su onClick="return goto();" type=button value=我要推广>
</p>
</FORM>
这是图形代码
需要实现的功能:
输入为空的时候 页面自动刷新一次
或者弹出提示框 “请输入查询名称”

㈥ PHP表单提交做判断的问题

64行有误,语法错误:

if(form.yzbm.value.length != 6 && form.yzbm.value != ){

另外给你一个我自己做项目经常用的验证方法:

<!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>My Check Form</title>
</head>
<script type="text/javascript">
//主函数
function CheckForm(oForm) {
var err_ele = null;
var ele = oForm.elements;
var haserror = false;
//遍历所有表元素
for(var i=0;i<ele.length;i++) {
//过滤元素类型
if(ele.type != 'submit' && ele.type != 'hidden' && ele.type != 'button') {
//是否需要验证标签
var required = ele[i].getAttribute('required');
if(required!="undefined" && (required==""||required=="true"||required=="yes") ) {
if(!validate(ele[i])) {
if(err_ele==null)
err_ele = ele[i];
haserror = true;
break;
}
}
}
}
//判断是否有没有通过验证的项目
if(haserror) {
err_ele.focus();
return false;
} else {
return true;
}
}

//得到表单元素的值
function getvalue(ele) {
var type = ele.getAttribute('type');
switch(type) {
case 'text':
case 'hidden':
case 'password':
case 'file':
case "select-one":
case 'textarea':
return ele.value;
}
}

//检测函数
function validate(ele) {
//得到设定的检测函数
var fun = ele.getAttribute('fun');
//自定义提示语句
var custommsg = ele.getAttribute('msg');

if(fun!=null) {
var checkarr = executeFunc(fun,ele);
if(checkarr[2] == 'regxp') { //正则表达式处理
if(!regValidate(getvalue(ele),checkarr[0])) {
//如果有自定义提示语句则使用自定义提示语句
if(custommsg) {
alert(custommsg);
} else {
alert(checkarr[1]);
}
return false;
}
} else if(checkarr[2] == 'custom') { //函数自行逻辑处理
//如果验证通过
if(!checkarr[0]) {
//如果有自定义提示语句则使用自定义提示语句
if(custommsg) {
alert(custommsg);
} else {
alert(checkarr[1]);
}
return false;
}
}
}
return true;
}

//运行函数
function executeFunc(name,element) {
//匹配函数是否带有参数
if(name.match(/^[\w]+\([\w,\'\"]+\);?$/)) {
return eval(name.replace(/^([\w]+)\(([\w,\'\"]+)\);?$/,'$1($2,element)'));
} else {
return eval(name.match(/^[\w]+\(\)$/) ? name : name + '(element)');
}
}

//
//判定某个值与表达式是否相符
function regValidate(value,sReg) {
//字符串->正则表达式,不区分大小写
var reg = new RegExp(sReg ,"i");
if(reg.test(value)) {
return true;
} else {
return false;
}
}

//////////////////////////////////验证规则定义///////////////////////////////

// 正则类验证
function UserName() {
var rt = new Array();
rt[0] = '^([a-zA-Z0-9]|[._]){4,19}$';
rt[1] = "用户名必须为4-19个字母和数字组成";
rt[2] = 'regxp';
return rt;
}

function PassWord() {
var rt = new Array();
rt[0] = '^([a-zA-Z0-9]|[._]){6,19}$';
rt[1] = "密码必须为6-19个字母和数字组成";
rt[2] = 'regxp';
return rt;
}

function notBlank(){
var rt = new Array();
rt[0] = "^\\S+$";
rt[1] = "该项不能为空,且不能含有空格!";
rt[2] = 'regxp';
return rt;
}

function required(){
var rt = new Array();
rt[0] = "^\\S";
rt[1] = "该项不能为空!";
rt[2] = 'regxp';
return rt;
}

//判断email
function isEmail() {
var rt = new Array();
rt[0] = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
rt[1] = "该项填写的EMAIL格式不正确!";
rt[2] = 'regxp';
return rt;
}

//只能输入中文
function onlyZh() {
var rt = new Array();
rt[0] = "^[\u0391-\uFFE5]+$";
rt[1] = "该项只能输入中文!";
rt[2] = 'regxp';
return rt;
}

//只可输入英文
function onlyEn() {
var rt = new Array();
rt[0] = "^[A-Za-z]+$";
rt[1] = "该项只能输入英文!";
rt[2] = 'regxp';
return rt;
}

function enOrNum() {
var rt = new Array();
rt[0] = "^[A-Za-z0-9]+$";
rt[1] = "该项只能输入英文和数字,且不能有空格!";
rt[2] = 'regxp';
return rt;
}

function isPhone() {
var rt = new Array();
rt[0] = "^((\\(\\d{2,3}\\))|(\\d{3}\\-))?(\\(0\\d{2,3}\\)|0\\d{2,3}-)?[1-9]\\d{6,7}(\\-\\d{1,4})?$";
rt[1] = "应输入正确的电话号码格式!";
rt[2] = 'regxp';
return rt;
}

// 自定义类验证函数
function isIdCard(ele) {
var rt = new Array();
rt[0] = false;
rt[1] = "应输入正确身份证号!";
rt[2] = 'custom';

var Reg_15 = /^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{2})(\w)$/;
var Reg_18 = /^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\w)$/;
var num = ele.value;
var len = num.length;

if (len == 15) {
if (Reg_15.test(num))
rt[0] = true;
}
else if(len == 18) {
if (Reg_18.test(num))
rt[0] = true;
}
return rt;
}

function rePassword(ID,ele) {
var rt = new Array();
rt[0] = false;
rt[1] = "再次密码输入不一致!";
rt[2] = 'custom';

var password = document.getElementById(ID).value;
if(password != '' || ele.value != ''){
if(password == ele.value)
rt[0] = true;
}
return rt;
}
</script>

<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return CheckForm(this);">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="20%" align="right">用户名:</td>
<td><input type="text" name="username" id="username" required="true" fun="UserName" msg="自定义提示信息:用户名不正确,请重新输入!" /></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="password" id="password" required="true" fun="PassWord" /></td>
</tr>
<tr>
<td align="right">确认密码:</td>
<td><input type="password" name="repassword" id="repassword" required="true" fun="rePassword('password')" /></td>
</tr>
<tr>
<td align="right">电子邮件:</td>
<td><input type="text" name="email" id="email" required="true" fun="isEmail" /></td>
</tr>
<tr>
<td align="right">身份证号:</td>
<td><input type="text" name="idcard" id="idcard" required="true" fun="isIdCard" /></td>
</tr>
<tr>
<td align="right">全中文项:</td>
<td><input type="text" name="chinese" id="chinese" required="true" fun="onlyZh" /></td>
</tr>
<tr>
<td align="right">其它:</td>
<td><input type="text" name="notblank" id="notblank" required="true" fun="notblank" /></td>
</tr>
<tr>
<td align="right"></td>
<td><input type="submit" name="button" id="button" value="提交" /></td>
</tr>
</table>
</form>

</body>
</html>

㈦ thinkPHP3.2.3利用Ajax前台实现验证码验证,但通过form表单的按钮提交后,验证码一直错误!如何解决

验证码一直错误那就是:后台生成的和前台显示的不是同一个验证码,你可以把后台生成的打印出来测试一下。

1:验证码生成代码:
//输入验证码
function verifyimg(){
//验证码做配置
$config = array(
'seKey' => 'ThinkPHP.CN', // 验证码加密密钥
'codeSet' => '', // 验证码字符集合
'expire' => 1800, // 验证码过期时间(s)
'useZh' => false,
'useImgBg' => false, // 使用背景图片
'fontSize' => 14, // 验证码字体大小(px)
'useCurve' => true, // 是否画混淆曲线
'useNoise' => true, // 是否添加杂点
'imageH' => 45, // 验证码图片高度
'imageW' => 100, // 验证码图片宽度
'length' => 4, // 验证码位数
'fontttf' => '4.ttf', // 验证码字体,不设置随机获取
'bg' => array(243, 251, 254), // 背景颜色
'reset' => true, // 验证成功后是否重置
);

$verify=new Verify($config); //实例化Verify类。 空间类元素引入。使用次数多的情况下。
//verify= new \Think\Verify 完全限定名称方式。 使用次数少的情况下。
$verify->entry(); //数据验证码。
}
2.下面的是一段验证码显示代码:
<ul>
<li class="user_main_text">验证码: </li>
<li class="user_main_input">
<input class="TxtValidateCodeCssClass" id="captcha" name="captcha" type="text">
验证码输出
<img src="{$smarty.const.__CONTROLLER__}/verifyimg" onclick="this.src='{$smarty.const.__CONTROLLER__}/verifyimg/'+Math.random()" alt="" />
</li>
</ul>
希望对你有帮助。

㈧ php怎样验证表单文本区域内容是否已存在数据库中

方法:查询数据,若数据存在则输出(前端这个要自己写,我只写了一个echo)

代码如下:

//$conn = new mysqli($sql_server_name, $sql_username, $sql_password, $sql_db);
$timu = $_GET["timu"];

$sql = $conn->query("查询 * from problems where timu
='". $timu . "'"); // 从problems库里查 注意把“查询”改成“select”,因为网络知道会屏蔽sql语句

if (mysqli_fetch_assoc($sql) > 0) {
echo "已存在";
} else {
echo "不存在";

}

㈨ php+mysql,提交数据后,成功提示和表单验证都在原链接上体现

这个你可以这么做,做一个判定,当未提交登陆的时候,现实登陆页面,登陆成功判定现实登陆子页面,失败显示失败页面,反馈值作为if判定依据,初始值为0,成功1,失败2,自然可以显示你需要的功能,类似效果页面是你看看世纪佳缘那种效果,那网站就是用php做的。

阅读全文

与php表单提交前验证相关的资料

热点内容
压缩因子定义 浏览:967
cd命令进不了c盘怎么办 浏览:212
药业公司招程序员吗 浏览:973
毛选pdf 浏览:659
linuxexecl函数 浏览:727
程序员异地恋结果 浏览:374
剖切的命令 浏览:228
干什么可以赚钱开我的世界服务器 浏览:290
php备案号 浏览:990
php视频水印 浏览:167
怎么追程序员的女生 浏览:487
空调外压缩机电容 浏览:79
怎么将安卓变成win 浏览:459
手机文件管理在哪儿新建文件夹 浏览:724
加密ts视频怎么合并 浏览:775
php如何写app接口 浏览:804
宇宙的琴弦pdf 浏览:396
js项目提成计算器程序员 浏览:944
pdf光子 浏览:834
自拍软件文件夹名称大全 浏览:328