0

I have made a simple Student Management system using php, JavaScript and CSS. I want to be able to reload the php pages within my system but keep the php sessions that I have set.

Any Solutions?

Here is a snippet of code from a php page. I made a button to go back to the previous page.

<html>
<button class= "submit" onclick="GoBack();">Back To Home Page</button>
</html>

I searched on the internet for a bit and tried to use the event.preventDefault method. It did not work.

`<script>
function GoBack(event,inputText){
window.location="AdminHomePage.php";

event.preventDefault();
}
</script>`

Any Solutions?

I made a login Page in this system and connected it to a database in HeidiSQL using MySQL.

The program checks if these values entered in the login page is in the database. If it is, it is put in a associative array.

if ($num == 1) {

        $d = $rs->fetch_assoc();

        $_SESSION["t"] = $d;
  • Hi there, I see no code/example about what your definition of a session is, if you're talking about [session_start()](https://www.php.net/manual/en/function.session-start.php), then it should retain the data between page loads. is your "app" primarily in the PHP code or the JavaScript code ? – Scuzzy Mar 03 '23 at 06:20
  • it uses both PHP and Javascript. – Trying_to_program Mar 04 '23 at 18:25
  • Well PHP has its sessions mechanism to retain data between hard page loads. and JavaScript has a number of ways to track data during execution, you need to learn how its various storage API's work, eg [local storage](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API) to figure out how this is going to work in your application. – Scuzzy Mar 05 '23 at 22:03

1 Answers1

0

PHP sessions belong to the server side. Even if you reload a page, the session is maintained.

If you are losing session data on reload, you need to debug your code that starts the session and stores the data into it.

Ryan M
  • 18,333
  • 31
  • 67
  • 74