Автоматическое создание страниц после отправки формы с использованием PHP

Чтобы автоматически создать страницу после того, как пользователь заполнил форму с помощью PHP, можно использовать несколько методов. Давайте рассмотрим некоторые из них:

  1. Использование функции заголовка PHP:

    <?php
    // Process the form submission and store the data
    // ...
    
    // Redirect the user to the dynamically generated page
    header("Location: generated_page.php");
    exit;
    ?>
  2. Использование JavaScript для перенаправления:

    <?php
    // Process the form submission and store the data
    // ...
    ?>
    
    <script>
    // Redirect the user to the dynamically generated page
    window.location.href = "generated_page.php";
    </script>
  3. Сохранение данных формы в переменной сеанса:

    <?php
    // Start the session
    session_start();
    
    // Process the form submission and store the data
    // ...
    
    // Store the form data in a session variable
    $_SESSION['form_data'] = $_POST;
    
    // Redirect the user to the dynamically generated page
    header("Location: generated_page.php");
    exit;
    ?>
  4. Хранение данных формы в базе данных:

    <?php
    // Process the form submission and store the data in a database
    // ...
    
    // Get the ID of the newly created entry
    $entryId = $pdo->lastInsertId();
    
    // Redirect the user to the dynamically generated page, passing the entry ID as a parameter
    header("Location: generated_page.php?id=" . $entryId);
    exit;
    ?>

Это всего лишь несколько примеров того, как можно автоматически генерировать страницу после того, как пользователь заполняет форму с помощью PHP. Выберите метод, который лучше всего соответствует вашим требованиям и применению.