Помогите с кодом

SR
На сайте с 05.11.2020
Offline
0
144

 Здравствуйте пацаны, решил сделать себе скрипт комментариев на сайт, но возникла проблема при добавлении комментарии открывается пустая страница, и приходит нажимать назад и обновлять страницу после этого появляется комментарий, и ещё когда я обновляю пустую страницу комментарии повторяются 

SR
На сайте с 05.11.2020
Offline
0
#1
<?php

//This part of the code writes the comment to a text file

$name =  $comment =  ""; // Creates the variables and makes them blank

if ($_SERVER["REQUEST_METHOD"] == "POST") { // If the post button is pressed

function format($data) {
$data = trim($data); // Trims the data 
$data = stripslashes($data); // Un-quotes the data (Do not change this)
$data = htmlspecialchars($data); // Protects against characters that would break the code
return $data; // Gives back the data
  
}

$comment = format($_POST["comment"]); // Formats the comment
$name = format($_POST["name"]); // Formats the name
 
if($comment != "") { // If the user has typed something into the comment box
if($name == "")     { // If there is no name
$name = "Anonymous"; // Set the name to Anonymous
}
// These just turn ASCII emoticons in to unicode ones
$comment = str_replace("&gt;:(","&#128545;",$comment);
$comment = str_replace(":(","&#128577;",$comment);
$comment = str_replace(":)","&#128522;",$comment);
$comment = str_replace(";)","&#128521;",$comment);
$comment = str_replace(":v","&#128527;",$comment);
$comment = str_replace(":D","&#128516;",$comment);

$date = date("d.m.Y"); // Generate the current date
$file = file_get_contents("chat.txt"); // Defines the file in wich comments are stored
$datarray = unserialize($file); // Turns the files contents into an array

$full = array // Combines all the data into an array
($date, $name, $comment);
$datarray[] = $full; // Adds this array to a bigger array of all the comments
$newfile = serialize($datarray); // Turns the array into a string we can store

file_put_contents("chat.txt", $newfile); // Stores the string into the file

function Redirect($url, $permanent = false) // Refreshes the page so the comment appears(and removes the old data so you dont post the same comment again on refresh)
{
    if (headers_sent() === false)
    {
        header('Location: ' . $url, true, ($permanent == true) ? 301 : 302);
    }

    exit();
}

Redirect('http://galashki.ru/comment/)', false);
}
}
// The bottom html code is the comment submitting box

?>
SR
На сайте с 05.11.2020
Offline
0
#2
Вот код в чем ошибка? 
M
На сайте с 04.12.2013
Offline
223
#3
SupeR-InG #:
Вот код в чем ошибка?

Не считая того, что вы комменты в текстовом файле храните? 😀

Что за скобка в адресе редиректа?

P.S. Dr.Web блокирует ваш сайт 😉

Домены и скрипт для коротких ссылок: https://u75.ru/domains-for-shortcuts

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий