Обучение/Помощь новичкам | ИИ Эпоха, помощь или консультация по php
Прошлый оригинальный код чата скрипта разрушители версия php 7.4.33
<?
include './system/common.php';
include './system/functions.php';
include './system/user.php';
if(!$user) {
header('location: /');
exit;}
$act = isset($_GET['act']) ? $_GET['act'] : null;
switch($act)
{
default: //Главнвя
$title = 'Общий чат';
include './system/h.php';
echo '<div class="title">'.$title.'</div>';
if($user['level'] < 3 AND $user['access'] == 0) {
echo '<div class="empty_block item_center"> Писать в чат можно с <img src="/images/ico/png/up.png" alt="*"> 3 уровня</div>
<div class="line"></div>';
}else{
$text = _string($_POST['text']);
$to = _string(_num($_GET['to']));
if($to) {
$_to = DB::Query('SELECT * FROM `users` WHERE `id` = "'.$to.'"');
$_to = mysqli_fetch_array($_to);
if(!$_to OR $_to['id'] == $user['id']) {
header('location: /chat/'.($_GET['clan'] == true ? 'clan/':''));
exit;}
}
if(isset($_REQUEST['text'])){
$antiflood = mysqli_fetch_array(DB::Query('SELECT * FROM `chat` WHERE `user` = \''.$user['id'].'\' ORDER BY `time` DESC LIMIT 1'));
if(empty($text) or mb_strlen($text,'UTF-8') < 1){
header("Location: ?");
$_SESSION['mes'] = mes('Пустое сообщение!');
exit;}
if(time() - $antiflood['time'] < 0){
header("Location: ?");
$_SESSION['mes'] = mes('Нельзя писать так часто!');
exit;
}
Новый код который делал через ИИ тот же код чата под версию php 8.4.20
<?php
include_once './system/common.php';
include_once './system/functions.php';
include_once './system/user.php';
// Доступно только для авторизованных пользователей
if (!isset($user) || !$user) {
if (ob_get_length()) {
ob_end_clean();
}
header('Location: /');
exit;
}
$user_id = (int)$user['id'];
$act = $_GET['act'] ?? '';
switch ($act) {
default: // Главная страница общего игрового чата
$title = 'Общий чат';
include_once './system/h.php';
echo '<div class="title">' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</div>';
if ((int)($user['level'] ?? 1) < 3 && (int)($user['access'] ?? 0) === 0) {
echo '<div class="empty_block item_center"> Писать в чат можно с <img src="/images/ico/png/up.png" alt="*"> 3 уровня</div>
<div class="line"></div>';
} else {
$text = isset($_POST['text']) ? _string($_POST['text']) : '';
$get_to = isset($_GET['to']) ? _num($_GET['to']) : 0;
$to = _string($get_to);
$_to = []; // Строгая инициализация во избежание Warning на PHP 8.4.20
if (!empty($to) && (int)$to > 0) {
$to_user_q = DB::safeQuery('SELECT * FROM `users` WHERE `id` = ? LIMIT 1', [(int)$to]);
$to_data = mysqli_fetch_array($to_user_q, MYSQLI_ASSOC);
if ($to_data) {
$_to = $to_data;
}
if (!$_to || (int)$_to['id'] === $user_id) {
$clan_redirect = (isset($_GET['clan']) && (string)$_GET['clan'] === 'true') ? 'clan/' : '';
if (ob_get_length()) { ob_end_clean(); }
header('Location: /chat/' . $clan_redirect);
exit;
}
}
// ОБРАБОТКА ОТПРАВКИ СООБЩЕНИЯ В ЧАТ
if (isset($_REQUEST['text'])) {
$antiflood_q = DB::safeQuery('SELECT `time` FROM `chat` WHERE `user` = ? ORDER BY `time` DESC LIMIT 1', [$user_id]);
$antiflood = mysqli_fetch_array($antiflood_q, MYSQLI_ASSOC);
$antiflood_time = (int)($antiflood['time'] ?? 0);
if (empty($text) || mb_strlen($text, 'UTF-8') < 1) {
$_SESSION['mes'] = mes('Пустое сообщение!');
if (ob_get_length()) { ob_end_clean(); }
header("Location: /chat/");
exit;
}
if (time() - $antiflood_time < 0) {
$_SESSION['mes'] = mes('Нельзя писать так часто!');
if (ob_get_length()) { ob_end_clean(); }
header("Location: /chat/");
exit;
}
======================================
Вопрос стоит использовать ИИ для улучшения кода если знаешь только базовые знания про php
<?
include './system/common.php';
include './system/functions.php';
include './system/user.php';
if(!$user) {
header('location: /');
exit;}
$act = isset($_GET['act']) ? $_GET['act'] : null;
switch($act)
{
default: //Главнвя
$title = 'Общий чат';
include './system/h.php';
echo '<div class="title">'.$title.'</div>';
if($user['level'] < 3 AND $user['access'] == 0) {
echo '<div class="empty_block item_center"> Писать в чат можно с <img src="/images/ico/png/up.png" alt="*"> 3 уровня</div>
<div class="line"></div>';
}else{
$text = _string($_POST['text']);
$to = _string(_num($_GET['to']));
if($to) {
$_to = DB::Query('SELECT * FROM `users` WHERE `id` = "'.$to.'"');
$_to = mysqli_fetch_array($_to);
if(!$_to OR $_to['id'] == $user['id']) {
header('location: /chat/'.($_GET['clan'] == true ? 'clan/':''));
exit;}
}
if(isset($_REQUEST['text'])){
$antiflood = mysqli_fetch_array(DB::Query('SELECT * FROM `chat` WHERE `user` = \''.$user['id'].'\' ORDER BY `time` DESC LIMIT 1'));
if(empty($text) or mb_strlen($text,'UTF-8') < 1){
header("Location: ?");
$_SESSION['mes'] = mes('Пустое сообщение!');
exit;}
if(time() - $antiflood['time'] < 0){
header("Location: ?");
$_SESSION['mes'] = mes('Нельзя писать так часто!');
exit;
}
Новый код который делал через ИИ тот же код чата под версию php 8.4.20
<?php
include_once './system/common.php';
include_once './system/functions.php';
include_once './system/user.php';
// Доступно только для авторизованных пользователей
if (!isset($user) || !$user) {
if (ob_get_length()) {
ob_end_clean();
}
header('Location: /');
exit;
}
$user_id = (int)$user['id'];
$act = $_GET['act'] ?? '';
switch ($act) {
default: // Главная страница общего игрового чата
$title = 'Общий чат';
include_once './system/h.php';
echo '<div class="title">' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</div>';
if ((int)($user['level'] ?? 1) < 3 && (int)($user['access'] ?? 0) === 0) {
echo '<div class="empty_block item_center"> Писать в чат можно с <img src="/images/ico/png/up.png" alt="*"> 3 уровня</div>
<div class="line"></div>';
} else {
$text = isset($_POST['text']) ? _string($_POST['text']) : '';
$get_to = isset($_GET['to']) ? _num($_GET['to']) : 0;
$to = _string($get_to);
$_to = []; // Строгая инициализация во избежание Warning на PHP 8.4.20
if (!empty($to) && (int)$to > 0) {
$to_user_q = DB::safeQuery('SELECT * FROM `users` WHERE `id` = ? LIMIT 1', [(int)$to]);
$to_data = mysqli_fetch_array($to_user_q, MYSQLI_ASSOC);
if ($to_data) {
$_to = $to_data;
}
if (!$_to || (int)$_to['id'] === $user_id) {
$clan_redirect = (isset($_GET['clan']) && (string)$_GET['clan'] === 'true') ? 'clan/' : '';
if (ob_get_length()) { ob_end_clean(); }
header('Location: /chat/' . $clan_redirect);
exit;
}
}
// ОБРАБОТКА ОТПРАВКИ СООБЩЕНИЯ В ЧАТ
if (isset($_REQUEST['text'])) {
$antiflood_q = DB::safeQuery('SELECT `time` FROM `chat` WHERE `user` = ? ORDER BY `time` DESC LIMIT 1', [$user_id]);
$antiflood = mysqli_fetch_array($antiflood_q, MYSQLI_ASSOC);
$antiflood_time = (int)($antiflood['time'] ?? 0);
if (empty($text) || mb_strlen($text, 'UTF-8') < 1) {
$_SESSION['mes'] = mes('Пустое сообщение!');
if (ob_get_length()) { ob_end_clean(); }
header("Location: /chat/");
exit;
}
if (time() - $antiflood_time < 0) {
$_SESSION['mes'] = mes('Нельзя писать так часто!');
if (ob_get_length()) { ob_end_clean(); }
header("Location: /chat/");
exit;
}
======================================
Вопрос стоит использовать ИИ для улучшения кода если знаешь только базовые знания про php
Yes, but not just «build me a website»; ideally, you should have the AI review your own code and constantly emphasize security, even though it does everything on its own
And, by the way, AI often can't fix even the simplest mistakes, like extra quotation marks or missing parentheses. Sometimes, it makes those same simple mistakes itself—the ones it can't find
ИИ правильно и четко выполняет свои задачи и во много раз ускоряет процесс разработки. Так если есть такая возможность есть почему её не использовать??
________
посл. ред. 10.06.2026 в 11:37; всего 1 раз(а); by Ramzesoff
Вопрос в другом стал ли код безопаснее после изменения ИИ чем был раньше ?