yii框架通过http协议获取地址栏中的内容
//创建一个控制器 <?php namespace frontend\controllers; use frontend\models\Zhuce; use Yii; use yii\web\Controller; use frontend\models\ContactForm; class LoginController extends Controller { //周考2 public function actionNn(){ $model = new Zhuce(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $aa=Yii::$app->request->post(); $data=$aa['Zhuce']; $data['rand']=rand(1111,9999); $data['time']=time(); ksort($data); //把数组变成地址栏的数据 $par=http_build_query($data); $str = md5($par); $secret='123456'; $sign=md5($str.$secret); //发送服务器端 curl // 创建一个新cURL资源 $ch = curl_init(); $header = [ 'sign:'.$sign, ]; curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1/month10/api.php?".$par); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch,CURLOPT_HTTPHEADER,$header); // curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); $init_last=curl_exec($ch); var_dump($init_last); } else { // 无论是初始化显示还是数据验证错误 return $this->render('login', ['model' => $model]); } } }
//创建一个api.php <?php /*var_dump($_GET);die; var_dump($_SERVER);*/ $secret='123456'; $data['name']=$_GET['name']; //var_dump($data['name']);die; $data['pwd']=$_GET['pwd']; $data['time']=$_GET['time']; $data['rand']=$_GET['rand']; $sign = $_SERVER['HTTP_SIGN']; ksort($data); $params = http_build_query($data); $str=md5($params); $newsign=md5($str.$secret); if($sign === $newsign) { //入库 } else { $arr=['status'=>500,'msg'=>'error']; } echo json_encode($arr);
你所浪费的今天是那些死去的人所奢望的明天,你所厌恶的现在是未来的你所回不去的曾经。