Transfer the user ' s data to another file



  • Got a page on the session. The user fills the form and data in the OBD system. The processor's on that page. How can the current user ' s ID be transmitted to the processor so that the data from the OBD user can be downloaded and the data recorded in the OBD user. Each user has its own table. How to read and record, I've figured it out. I can't give the ID to the user.



  • Способ 1 (небезопасный):

    //index.php
    //Каким-то образом знаем ИД текущего пользователя и пишем его в переменную
    $current_user_id = ...;
    
    <!-- Внутри html-формы выводим его в hidden-поле -->
    <!-- После сабмита этой формы значение этого поля придет в script.php -->
    <!-- Небезопасно тем, что пользователь может прямо в браузере подредактировать значение этого поля и отправить на сервер измененное значение-->
    <form action="script.php" method="post">
    <input type="hidden" name="current_user_id" id="current_user_id" value="<?= $current_user_id; ?>"/>
    ...
    ...
    </form>
    

    Accordingly, script.php:

    $current_user_id = $_POST['current_user_id'];
    

    Further request to the OBD.

    Способ 2:

    //index.php
    //Каким-то образом знаем ИД текущего пользователя
    $current_user_id = ...;
    session_start();
    // и пишем его в СЕССИЮ
    $_SESSION['current_user_id'] = $current_user_id;
    
    <!-- В форме уже ничего не прячем -->
    <form action="script.php" method="post">
    ...
    ...
    </form>
    

    script.php:

    session_start();
    //Получаем значение из сессии
    $current_user_id = $_SESSION['current_user_id'];
    

    Further request to the OBD.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2