百度验证文件上传辅助PHP文件(baidu.php)中的内容
百度验证文件上传辅助文件中的内容在本文中将会给大家讲解,大家了解就可以了不需要做深刻的理解!
不需要设置伪静态的baidu.php文件
我们软件将百度的验证文件上传到网站根目录,不需要设置伪静态,这种操作简单也便于理解
<?php $res = $_POST["vertify"]; $res2 = $_POST["vertify2"]; $res3 = $_POST["code_type"]; if($res3 == "1"){ $file = fopen("baidu_verify_codeva-".$res.".html",'w'); } else { $file = fopen("baidu_verify_code-".$res.".html",'w'); } fwrite($file,$res2); fclose($file); ?>
需要设置伪静态的baidu.php文件
如果需要设置伪静态,我们需要上传baidu.php文件到网站根目录,并且需要设置伪静态,伪静态需要在宝塔的网站配置伪静态中添加
<?php $req_url = $_SERVER["REQUEST_URI"]; if(strpos($req_url,'baidu_verify_') !== false) { $code = explode('-',$req_url)[1]; $code = str_replace('.html','',$code); $file = 'baidu_verify_datas_tmp'; $content = array(); if(file_exists($file)) { $content = json_decode(file_get_contents($file),TRUE); } $verify_code = empty($content[$code])? "verify_code不存在,请先设置" : $content[$code]; echo $verify_code; } else { $type = $_GET["type"]; $code = $_GET["code"]; $verify_code = $_GET["verify_code"]; $file = 'baidu_verify_datas_tmp'; $content = array(); if(file_exists($file)) { $content = json_decode(file_get_contents($file),TRUE); } $content[$code] = $verify_code; file_put_contents($file,json_encode($content)); } ?>
伪静态的内容
rewrite /baidu_verify_(.*?).html /baidu.php break;
作者建议大家使用非伪静态的方式,这样简单而且也便于理解,使用伪静态的方式只是可以使根目录看起来干净而已!