How to allow the user to return to the PHP page?

I completed a session in my application, but I need to allow a registered user to use the back button to go to previous pages. How can I make sure that the session does not expire and allows the user to view the previous page?

Here is my code

<?php
//Start session
    if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}
$User = $_SESSION["User"];
//Page content
?>

I started a session when I use the back button in the browser. I get a page that reads the session has expired. Which I do not want to happen.

+4
source share
3 answers

in your php at the top of each page, start a session before opening the tag <html>

<?php session_start(); ?>
<html>

set your session variables somewhere in your php, note that this value must be serializable

<?php $_SESSION["variable"] = "value"; ?>

, , , session_start();

<?php echo $_SESSION["variable"]; ?>

, .

:

, , , , :

  • ,
  • w/session

hiccup , "", . : fooobar.com/questions/79996/...

session_status. . session_start();

<?php
//Start session
session_start();
// User is either pulled from the session or is null
$User = $_SESSION["User"] ? !empty($_SESSION["User"]) : NULL;
//Page content
?>

if (session_status() !== PHP_SESSION_ACTIVE) { , - ( ), , .

+1

, .

, . , - - ( ).

+1

javascript, .

<button onclick="goBack()">Go Back</button>

<script>
function goBack() {
    window.history.back();
}
</script>
+1

All Articles