㈠ php驗證碼怎麼在前from表單驗證呢請大師請教,謝謝
把驗證碼的值當作一個參數存在html表單/ajax表單中(如,以vcode命名增加一個hiden text);
在控制器接收表單的邏輯,接收$_POST['vcode'],判斷$_POST['vcode']是不是生成的驗證碼,是,跳過,不是返回驗證碼錯誤到表單頁面;
其實驗證就類似介面一樣,雙方約定規則,統一密鑰,而驗證只是你自己去驗證罷了
㈡ 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做的。