這篇文章將為大家詳細(xì)講解有關(guān)php中如何使用token,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

具體如下:
一、token功能簡(jiǎn)述
PHP 使用token驗(yàn)證可有效的防止非法來(lái)源數(shù)據(jù)提交訪(fǎng)問(wèn),增加數(shù)據(jù)操作的安全性
二、實(shí)現(xiàn)方法:
前臺(tái)form表單:
<form action="do.php" method="POST"> <?php $module=mt_rand(100000,999999);?> <input type="text" name="sec_name" value=""/> <input type="hidden" name="module" value="<?php echo $module;?>"/> <input type="hidden" name="timestamp" value="<?php echo time();?>"/> <input type="hidden" name="token" value="<?php echo md5($module.'#$@%!^*'.time());?>"/> </form>
后臺(tái)do.php的token驗(yàn)證部分:
<?php
$module = $_POST['module'];
$timestamp = $_POST['timestamp'];
$token = md5($module.'#$@%!^*'.$timestamp);
if($token != $_POST['token']){
echo('非法數(shù)據(jù)來(lái)源');
exit();
}
$sec_name=$_POST['sec_name'];
//PHP數(shù)據(jù)處理.....
?>關(guān)于“php中如何使用token”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
當(dāng)前標(biāo)題:php中如何使用token-創(chuàng)新互聯(lián)
鏈接地址:http://chinadenli.net/article0/dpidoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、品牌網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、網(wǎng)站排名、全網(wǎng)營(yíng)銷(xiāo)推廣、App開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容
移動(dòng)網(wǎng)站建設(shè)知識(shí)