I have an calendar application that does look like this:
Calendar app.
The function I am implementing is the navigation through the months (previous month/next month) function.
During the implementation I have encountered a few problems:
- PHP cannot easily persist variables.
- Persistent values have to be deleted/removed when closing the tab/opening the page for the first time.
Adressing Issues
2. There are several ways to persist a variable:
Starting a session
session_start();
$_SESSION["favcolor1"] = "green";
echo $_SESSION["favcolor1"];
Issues
- The value persists, but the variables are nowhere to be found in the app memory.
- When closing the tab, the value remains, which is a problem.
Saving as cookie
setcookie("TestCookie", "Hello World", time()+3600);
echo $_COOKIE["TestCookie"];
The variable can be found in the app storage
Issues
- If there is an echo before setcookie, it will be cancelled, i.e. it will not be executed. (xDD).
- When closing the tab, it persists, which is a problem.
Other possible solutions
- External files, which should work with
include
and `define - Using a database to keep track of persistent variables.
2. Tab close event can be done via JS with beforeunload
??
Is there a way to do it via PHP ?
The problem persists:
- The variable should persist, which can be solved
- The values should be cancelled when the tab is closed.