php注册页面手机验证,PHP手机短信注册验证码,后台代码怎么写?

现在会员制的网站和app越来越多,基本上都要求客户手机注册,用户看起来很简单的一个流程,后台程序确十分复杂,身为PHP开发者,后台的相应代码如果写?今天我就来分享一下注册验证码相关demo

/* *

* 类名:smsApi

* 功能:硕达通短信接口请求类(网站:www.shdat.com)

* 详细:构造硕达通短信接口请求,获取远程HTTP数据

* 版本:1.0

* 日期:2017-02-19

* 说明:

* 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码。

* 该代码只是提供一个参考。

*/

class shuodaSmsApi {

//企业ID

private $userId;

//账号 替换成你自己的账号

private $account;

//密码 替换成你自己的密码

private $password;

//构造函数

public function __construct($userId,$account,$password){

$this->userId = $userId;

$this->account = $account;

$this->password = $password;

}

/**

* 发送短信

*

* @param string $mobile 手机号码

* @param string $content 短信内容(短信的内容,内容需要UTF-8编码)

* @param string $sendTime 定时发送时间(为空表示立即发送,定时发送格式2017-02-19 18:00:00)

* @param string $extno   扩展子号

*/

public function send($mobile,$content, $sendTime='', $extno=''){

//接口URL

$url = 'http://115.28.172.169:8888/sms.aspx';

$action = 'send';

$data = array (

'userid' => $this->userId,

'account' => $this->account,

'password' => $this->password,

'mobile' => $mobile,

'content' => $content,

'sendTime' => $sendTime,

'action' => $action,

'extno' => $extno

);

$result = $this->curl($url,$data);

return $result;

}

/**

*余额及已发送量查询接口

*

**/

public function overAge() {

$url = 'http://115.28.172.169:8888/sms.aspx';

$action = 'overage';

$data = array (

'userid' => $this->userId,

'account' => $this->account,

'password' => $this->password,

'action' => $action,

);

$result = $this->curl($url,$data);

return $result;

}

/**

*非法关键词查询接口

* @param string $content 检测发送内容

*/

public function checkKeyWord($content){

$url = 'http://115.28.172.169:8888/sms.aspx';

$action = 'checkkeyword';

$data = array (

'userid' => $this->userId,

'account' => $this->account,

'password' => $this->password,

'action' => $action,

'content' => $content,

);

$result = $this->curl($url,$data);

return $result;

}

/**

*状态报告接口

*

*/

public function queryStatus(){

$url = 'http://115.28.172.169:8888/statusApi.aspx';

$action = 'query';

$data = array (

'userid' => $this->userId,

'account' => $this->account,

'password' => $this->password,

'action' => $action,

);

$result = $this->curl($url,$data);

return $result;

}

/**

*上行接口

*

*/

public function call(){

$url = 'http://115.28.172.169:8888/callApi.aspx';

$action = 'query';

$data = array (

'userid' => $this->userId,

'account' => $this->account,

'password' => $this->password,

'action' => $action,

);

$result = $this->curl($url,$data);

return $result;

}

/**

* 通过CURL发送HTTP请求

* @param string $url  //请求URL

* @param array $postFields //请求参数

* @return mixed

*/

private function curl($url,$data,$method='get'){

$ch = curl_init ();

curl_setopt ( $ch, CURLOPT_HEADER, 0 );

curl_setopt ( $ch, CURLOPT_RETURNTRANSFER,1);

if($method=='get'){

$url = $url.'?'.http_build_query($data);

curl_setopt ($ch,CURLOPT_URL,$url);

}elseif($method=='post'){

curl_setopt($ch,CURLOPT_POST,1);

curl_setopt($ch,CURLOPT_POSTFIELDS,$data);

}

$result = curl_exec ( $ch );

curl_close ( $ch );

return $result;

}

}

?>

测试示例:

include('shuodaSdk.php');

$userId = '45';

$account = 'ceshi';

$password = 'CEshi123';

$shuodaSdk = new shuodaSmsApi($userId,$account,$password);

$mobile = '13800138000';

$content = '【硕达科技】您本次的验证码是:852369,如非本人请忽略';

$result = $shuodaSdk->send($mobile,$content);

//$result = $shuodaSdk->overAge();

//$result = $shuodaSdk->checkKeyWord('诈骗');

//$result = $shuodaSdk->queryStatus();

//$result = $shuodaSdk->call();

var_dump($result);

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的PHP后台管理员系统的登录页面代码,包含验证码功能: login.php ``` <?php session_start(); if(isset($_POST['submit'])){ $username = $_POST['username']; $password = $_POST['password']; $captcha = $_POST['captcha']; if(empty($username) || empty($password) || empty($captcha)){ $error = "所有字段都是必填项!"; } else { if($_SESSION['captcha'] != $captcha){ $error = "验证码不正确!"; } else { // 在此处添加数据库查询代码验证用户名和密码是否正确 // 如果正确,则将用户ID和用户名存储在SESSION中,并在此处进行重定向 $_SESSION['user_id'] = 1; $_SESSION['username'] = $username; header('Location: dashboard.php'); exit; } } } // 生成验证码 $length = 6; $captcha = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length); $_SESSION['captcha'] = $captcha; ?> <!DOCTYPE html> <html> <head> <title>管理员登录</title> </head> <body> <h1>管理员登录</h1> <?php if(isset($error)): ?> <p><?php echo $error; ?></p> <?php endif; ?> <form method="post"> <label for="username">用户名:</label> <input type="text" name="username" id="username"><br><br> <label for="password">密码:</label> <input type="password" name="password" id="password"><br><br> <label for="captcha">验证码:</label> <input type="text" name="captcha" id="captcha"> <img src="captcha.php" alt="验证码"><br><br> <input type="submit" name="submit" value="登录"> </form> </body> </html> ``` captcha.php ``` <?php session_start(); $length = 6; // 验证码长度 $captcha = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length); $_SESSION['captcha'] = $captcha; $img = imagecreate(100, 30); // 创建一个100x30像素的图像 $bg_color = imagecolorallocate($img, 255, 255, 255); // 设置背景颜色为白色 $text_color = imagecolorallocate($img, 0, 0, 0); // 设置文本颜色为黑色 imagestring($img, 5, 20, 10, $captcha, $text_color); // 将验证码绘制到图像上 header('Content-Type: image/jpeg'); // 设置响应类型为JPEG图像 imagejpeg($img); // 输出图像 imagedestroy($img); // 释放内存 ?> ``` 在上述代码中,我们首先在`login.php`中生成了一个随机字符串作为验证码,并将其存储在SESSION变量`$_SESSION['captcha']`中。然后,在表单中显示一个输入框和一个图像,其中图像的`src`属性指向`captcha.php`文件。`captcha.php`文件将生成一个100x30像素的图像,并在图像上绘制验证码。最后,我们在`login.php`文件中检查用户输入的验证码是否与SESSION变量中的验证码匹配。如果匹配,则进行身份验证并将用户ID和用户名存储在SESSION中,然后将用户重定向到`dashboard.php`。如果验证码不匹配,则显示错误消息。 请注意,此代码仅提供了一个基本的验证机制,可能需要进行修改以适应您的特定需求。例如,您可能需要将用户名和密码存储在数据库中,并使用数据库查询来验证它们。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值