/
maxavangard
/
KTC
Обзор
Документация
Войти
/
maxavangard
/
KTC
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
controllers/SiteController.php
95 строк
2 KB
Avangartd
first_commit
28 июн 2026, 18:48
28 июн 2026, 18:48
f36fb03
Код
Авторство
О чём код?
<?php namespace app\controllers; use Yii; use yii\web\Controller; use app\models\History; class SiteController extends Controller { public function actionIndex() { $result = null; if (Yii::$app->request->isPost) { if (Yii::$app->user->isGuest) { return $this->render('index', [ 'result' => null, 'showModal' => true ]); } $url = $_POST['url']; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_exec($ch); $httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); curl_close($ch); if ($httpCode == 200) { $status = 'ONLINE'; } else { $status = 'OFFLINE'; } $result = [ 'url' => $url, 'code' => $httpCode, 'status' => $status ]; $history = new History(); $history->user_id = Yii::$app->user->id; $history->url = $url; $history->http_code = $httpCode; $history->status = $status; $history->created_at = date('Y-m-d H:i:s'); $history->save(); } return $this->render('index', [ 'result' => $result, 'showModal' => false ]); } public function actionCabinet() { $history = History::find() ->where([ 'user_id' => Yii::$app->user->id ]) ->all(); return $this->render('cabinet', [ 'history' => $history ]); } public function actionError() { return $this->renderContent('error'); } }