user2986042 user2986042 - 2 months ago 6
HTML Question

How can i maintain a session for a HTML page in Apache server?

I am new in session management for website. I created a simple Form page with all the data. After clicking submit button, my forms input fields will disable. And the submit button changes to disconnect. This is working fine with Apache server.

Now i want a solution that when I refresh this page or load a same page in new tab, I need to show the same disabled for page. Means, do not refresh the page. I need to maintain this page when user press disconnect button. Should I use database with login details?

Any suggestions? or tutorials links?

Answer

sessions are not managed by html files. You'll need to create php files like this:

<?php
session_start(); // without this, you won't have any session
// add here code to manage your session/post data
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $_SESSSION['title'] = strip_tags($_POST['title']);
}
?>
<html>
...
<body>
<form action="" method="post">
<input type="text" name="title" value="<?php echo $_SESSION['title']; ?>" />
<input type="submit" value="Save" />
</form>

In above example the submit will be made in the same page.

Resources: https://www.tutorialspoint.com/php/php_sessions.htm

http://www.w3schools.com/php/php_sessions.asp

http://www.w3schools.com/php/php_forms.asp

Don't use this in production. This example is for demonstration purpose only.