'How destroy a php session after variable is shown

i have 2 php page, First page ;

  session_start();
  $_SESSION["firstname"] = "Peter";
  $_SESSION["lastname"] = "Parker";

  header('Location: http://quebecprohockeyleague.com/simulation/team/training');

Seconde Page ;

  if (!isset($_SESSION)) { session_start(); }
  if (isset($_SESSION["firstname"])) {
    echo 'Hi, ' . $_SESSION["firstname"] . ' ' . $_SESSION["lastname"];
    session_destroy();
  }

The problem is when i remove session_destroy(); the text show everytime, and when session_destroy(); is there, the text dont show at all.

I want to destroy the session after the text is show ? it is possible ? Thanks in advance

php


Solution 1:[1]

store session value in a variable before showing the data and then destroy the session after that you can use that varaible to print the value

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Salman ansari