㈠ php驗證碼 實現點擊刷新
隨機產生的驗證碼放在一個文件1中
在另一個文件中引用文件1
<img src="code.php" onClick="this.src='code.php?nocache='+Math.random()" style="cursor:hand" alt="點擊換一張"/>
實現點擊圖片自動刷新圖片
㈡ 如何實現php手機簡訊驗證功能
現在網站在建設網站時為了保證用戶信息的真實性,往往會選擇發簡訊給用戶手機發驗證碼信息,只有通過驗證的用戶才可以注冊,這樣保證了用戶的聯系信息資料的100%的准確性。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >
<html xmlns>
<head>
<title></title>
<script src="js/jquery-1.4a2.min.js" type="text/javascript"></script>
<script type="text/javascript">
/*-------------------------------------------*/
var InterValObj; //timer變數,控制時間
var count = 60; //間隔函數,1秒執行
var curCount;//當前剩餘秒數
var code = ""; //驗證碼
var codeLength = 6;//驗證碼長度
function sendMessage() {
curCount = count;
var dealType; //驗證方式
tel = $(』#tel』).val();
if(tel!=』』){
//驗證手機有效性
var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+d{8})$/;
if(!myreg.test($(』#tel』).val()))
{
alert(』請輸入有效的手機號碼!』);
return false;
}
tel = $(』#tel』).val();
//產生驗證碼
for (var i = 0; i < codeLength; i++) {
code += parseInt(Math.random() * 9).toString();
}
//設置button效果,開始計時
$("#btnSendCode").attr("disabled", "true");
$("#btnSendCode").val("請在" + curCount + "秒內輸入驗證碼");
InterValObj = window.setInterval(SetRemainTime, 1000); //啟動計時器,1秒執行一次
//向後台發送處理數據
$.ajax({
type: "POST", //用POST方式傳輸
dataType: "text", //數據格式:JSON
url: 』yanzhengma.php』, //目標地址(根據實際地址)
data: "&tel=" + tel + "&code=" + code,
error: function (XMLHttpRequest, textStatus, errorThrown) { },
success: function (msg){ }
});
}else{
alert(』請填寫手機號碼』);
}
}
//timer處理函數
function SetRemainTime() {
if (curCount == 0) {
window.clearInterval(InterValObj);//停止計時器
$("#btnSendCode").removeAttr("disabled");//啟用按鈕
$("#btnSendCode").val("重新發送驗證碼");
code = ""; //清除驗證碼。如果不清除,過時間後,輸入收到的驗證碼依然有效
}
else {
curCount--;
$("#btnSendCode").val("請在" + curCount + "秒內輸入驗證碼");
}
}
</script>
</head>
<body>
<input name="tel" id=tel type="text" />
<input id="btnSendCode" type="button" value="發送驗證碼" onclick="sendMessage()" /></p>
</body>
</html>
第三、調用簡訊伺服器簡訊介面
整理的頁面是yanzhengma.php(具體根據服務商提供信息)
<?php //提交簡訊
$post_data = array();
$post_data[』userid』] =簡訊服務商提供ID;
$post_data[』account』] = 』簡訊服務商提供用戶名』;
$post_data[』password』] = 』簡訊服務商提供密碼』;
// Session保存路徑
$sessSavePath = dirname(__FILE__)."/../data/sessions/";
if(is_writeable($sessSavePath) && is_readable($sessSavePath)){
session_save_path($sessSavePath);
}
session_register(』mobliecode』);
$_SESSION[』mobilecode』] = $_POST["code"];
$content=』簡訊驗證碼:』.$_POST["code"].』【簡訊驗證】』;
$post_data[』content』] = mb_convert_encoding($content,』utf-8』, 』gb2312』); //簡訊內容需要用urlencode編碼下
$post_data[』mobile』] = $_POST["tel"];
$post_data[』sendtime』] = 』』; //不定時發送,值為0,定時發送,輸入格式YYYYMMDDHHmmss的日期值
$url=』http://IP:8888/sms.aspx?action=send』;
$o=』』;
foreach ($post_data as $k=>$v)
{
$o.="$k=".$v.』&』;
}
$post_data=substr($o,0,-1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要將結果直接返回到變數里,那加上這句。
$result = curl_exec($ch);
?>
第四:提交表單信息時對簡訊驗證碼驗證
//手機驗證碼開始
session_start();
$svalitel = $_SESSION[』mobilecode』];
$vdcodetel = empty($vdcodetel) ? 』』 : strtolower(trim($vdcodetel));
if(strtolower($vdcodetel)!=$svalitel || $svalitel==』』)
{
ResetVdValue();
//echo "Pageviews=".$vdcodetel;
ShowMsg("手機驗證碼錯誤!", 』-1』);
exit();
}
㈢ php怎麼編寫手機簡訊驗證碼功能
以前在遠標做過你的應用應該是這樣吧,用戶輸入手機號碼,點擊發送簡訊,用戶收到驗證碼,輸入對應的驗證碼 判斷是否正確。
需要:
申請一個簡訊介面,就是點擊發送驗證碼的時候,提交到介面給該號碼下發驗證碼。
技術方面的實現:
1、點擊獲取驗證碼
2、程序ajax post提交到簡訊介面
3、簡訊介面服務商 介面判斷用戶和口令,正確後,下發簡訊給該號碼。
4、用戶輸入號碼,程序判斷驗證碼是否一致。
㈣ 我的php代碼中登陸界面加一個驗證碼,如何實現
php登陸頁面+驗證碼的實現,參考如下:
1、首先新建一個php站點;
㈤ PHP如何生成加減演算法方式的驗證碼
<?php
namespace mobile\components;
/**
* @author fenghuo
*
* 改造的加減法驗證類
* 使用示例 VerifyCode::get(1,2);
* 驗證示例 VerifyCode::check($code);
*/
class VerifyCode
{
/**
* php驗證碼
*/
public static function get($one,$two,$prefix = '', $font_size = 28)
{
//文件頭...
ob_get_clean();
header("Content-type: image/png;charset=utf-8;");
//創建真彩色白紙
$width = $font_size*5;
$height = $font_size+1;
$im = @imagecreatetruecolor($width, $height) or die("建立圖像失敗");
//獲取背景顏色
$background_color = imagecolorallocate($im, 255, 255, 255);
//填充背景顏色
imagefill($im, 0, 0, $background_color);
//獲取邊框顏色
$border_color = imagecolorallocate($im, 200, 200, 200);
//畫矩形,邊框顏色200,200,200
imagerectangle($im,0,0,$width - 1, $height - 1,$border_color);
//逐行炫耀背景,全屏用1或0
for($i = 2;$i < $height - 2;$i++) {
//獲取隨機淡色
$line_color = imagecolorallocate($im, rand(200,255), rand(200,255), rand(200,255));
//畫線
imageline($im, 2, $i, $width - 1, $i, $line_color);
}
//設置印上去的文字
$firstNum = $one;
$secondNum = $two;
$actionStr = $firstNum > $secondNum ? '-' : '+';
//獲取第1個隨機文字
$imstr[0]["s"] = $firstNum;
$imstr[0]["x"] = rand(2, 5);
$imstr[0]["y"] = rand(1, 4);
//獲取第2個隨機文字
$imstr[1]["s"] = $actionStr;
$imstr[1]["x"] = $imstr[0]["x"] + $font_size - 1 + rand(0, 1);
$imstr[1]["y"] = rand(1,5);
//獲取第3個隨機文字
$imstr[2]["s"] = $secondNum;
$imstr[2]["x"] = $imstr[1]["x"] + $font_size - 1 + rand(0, 1);
$imstr[2]["y"] = rand(1, 5);
//獲取第3個隨機文字
$imstr[3]["s"] = '=';
$imstr[3]["x"] = $imstr[2]["x"] + $font_size - 1 + rand(0, 1);
$imstr[3]["y"] = 3;
//獲取第3個隨機文字
$imstr[4]["s"] = '?';
$imstr[4]["x"] = $imstr[3]["x"] + $font_size - 1 + rand(0, 1);
$imstr[4]["y"] = 3;
//文字
$text = '';
//寫入隨機字串
for($i = 0; $i < 5; $i++) {
//獲取隨機較深顏色
$text_color = imagecolorallocate($im, rand(50, 180), rand(50, 180), rand(50, 180));
$text .= $imstr[$i]["s"];
//畫文字
imagechar($im, $font_size, $imstr[$i]["x"], $imstr[$i]["y"], $imstr[$i]["s"], $text_color);
}
session_start();
$_SESSION[$prefix.'verifycode'] = $firstNum > $secondNum ? ($firstNum - $secondNum) : ($firstNum + $secondNum);
//顯示圖片
ImagePng($im);
//銷毀圖片
ImageDestroy($im);
}
public static function check($code)
{
if(trim($_SESSION[$prefix.'verifycode']) == trim($code)) {
return true;
} else {
return false;
}
}
㈥ 怎樣用PHP製作驗證碼
<?php
//驗證碼類
classValidateCode{
private$charset='';//隨機因子
private$code;//驗證碼
private$codelen=4;//驗證碼長度
private$width=90;//寬度
private$height=40;//高度
private$img;//圖形資源句柄
private$font;//指定的字體
private$fontsize=20;//指定字體大小
private$fontcolor;//指定字體顏色
//構造方法初始化
publicfunction__construct(){
$this->font=dirname(__FILE__).'/font/elephant.ttf';//注意字體路徑要寫對,否則顯示不了圖片
}
//生成隨機碼
privatefunctioncreateCode(){
$_len=strlen($this->charset)-1;
for($i=0;$i<$this->codelen;$i++){
$this->code.=$this->charset[mt_rand(0,$_len)];
}
}
//生成背景
privatefunctioncreateBg(){
$this->img=imagecreatetruecolor($this->width,$this->height);
$color=imagecolorallocate($this->img,mt_rand(157,255),mt_rand(157,255),mt_rand(157,255));
imagefilledrectangle($this->img,0,$this->height,$this->width,0,$color);
}
//生成文字
privatefunctioncreateFont(){
$_x=$this->width/$this->codelen;
for($i=0;$i<$this->codelen;$i++){
$this->fontcolor=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imagettftext($this->img,$this->fontsize,mt_rand(-30,30),$_x*$i+mt_rand(1,5),$this->height/1.4,$this->fontcolor,$this->font,$this->code[$i]);
}
}
//生成線條、雪花
privatefunctioncreateLine(){
//線條
for($i=0;$i<6;$i++){
$color=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$color);
}
//雪花
for($i=0;$i<100;$i++){
$color=imagecolorallocate($this->img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
imagestring($this->img,mt_rand(1,5),mt_rand(0,$this->width),mt_rand(0,$this->height),'*',$color);
}
}
//輸出
privatefunctionoutPut(){
header('Content-type:image/png');
imagepng($this->img);
imagedestroy($this->img);
}
//對外生成
publicfunctiondoimg(){
$this->createBg();
$this->createCode();
$this->createLine();
$this->createFont();
$this->outPut();
}
//獲取驗證碼
publicfunctiongetCode(){
returnstrtolower($this->code);
}
}
㈦ 請教網頁製作中PHP驗證碼實現問題。
在文件1用表單提交給文件2,輸入驗證碼肯定是在表單的輸入框里,輸入好後提交表單時對象是文件2就行了。注意php需要伺服器支持啊,沒伺服器直接當文本打開了。
㈧ 用PHP技術製作驗證碼遇到的問題。
用JS,<input type="text" name="yzm" size=5 /> <a href="#"><img src="yzm.php" onclick="this.src='yzm.php?id='+Math.random();" /></a> 如看不清楚,請點擊圖片刷新
這個是我寫過的,給你點啟發吧
㈨ php驗證碼怎麼使用
調用你這個代碼里已經生成的驗證碼,我給你的是用戶輸入時候的頁面,你還要再寫一個驗證的頁,就是驗證用戶輸入的和代碼生成的是否一樣 <form action="**.php" method="post"> <table> <tr> <td width="490" align="left"> <input size="8" name="$vcode" /> <img src="./verifyImg.php"(比如說這個是你的文件的文件名) onClick="this.src='./verifyImg.php?=random'+Math.random();" style="cursor:pointer;"> <span>點擊切換圖片</span><br /> <input type="submit" value="提交" /> </td></tr></table>
㈩ php如何實現郵箱驗證
這是一個可以發送郵件的程序。程序是直接使用SMTP協議進行發送,用到了經典的phpMailer庫。
請閱讀apply.php文件。
發郵件之前你需要一個用來發送郵件的郵箱賬號。但不能使用這個賬號發送太多的郵件,否則會被當做垃圾郵件屏蔽。如果發送量較大,可以多申請幾個郵箱。
關鍵變數說明:
subject: 郵件的主題
email: 郵件的內容
host: SMTP主機,與你申請的郵箱的服務商有關,詳見代碼內注釋
fromname: 發件人的名字,可以任意寫,對方收到時能看到這個名字
from: 發件人地址
to: 收件人地址,代碼中寫了$to = $from,請自行更改
username和password: 你郵箱的賬號和密碼,一般username都等於發件人地址。必須提供,否則無法發送郵件。
PHPMailer說明:
$mailer = new PHPMailer(true);
$mailer->IsHTML(true); // 這是一封HTML郵件
$mailer->IsSMTP(true); // 連接SMTP服務發送郵件
# $mailer->SMTPDebug = true; // 是否開啟調試模式
$mailer->CharSet = 'UTF-8'; // 郵件內容的編碼,和你程序的編碼保持一致
$mailer->Encoding = 'base64'; // 郵件傳遞過程使用的編碼
$mailer->FromName = $fromname; // 發件人
$mailer->Host = $host; // SMTP服務地址
$mailer->AddAddress($to); // 添加收件人
$mailer->From = $from; // 設置發件人
$mailer->Subject = $subject; // 設置主題
$mailer->MsgHTML($email); // 設置HTML郵件內容
$mailer->SMTPAuth = true; // 開啟SMTP驗證
$mailer->Username = $username; // 設置用戶名
$mailer->Password = $passwd; // 設置密碼
$mailer->Send(); // 發送郵件