Software: latest Apache and PHP on local Manjaro server.
Web browsers: Waterfox and Basilisk.
Trying my hand at converting a few of my sites to linux apache/php after 20-odd years of programming in (expletives) ASP.
First site is fine - just a small, basic one but it works. So I began work on a control panel for it to manage MySql (actually MariaDB), a "copy" of a control panel I designed in ASP years ago.
Much easier to build than in Classic ASP but I cannot get the sessions to stick. The initial problem was discovering that save_path() does not know about full absolute paths. I eventually set up a tmp session folder in the web directory's root and that now works.
Having got that sorted I have another problem. Every time I reload the login page it starts a new session. And if I load the page anew using the browser's URL bar (instead of the reload button) it opens a new tab. I've read at least a couple of hundred forums and manual pages over the past week for this and the save_path() problem and am still puzzled.
My basic starting code at the start of the site's page, before anything else, is:
session_save_path('/srv/tmp/php_session');
ini_set('session.gc_probablilty',1);
session_start();
One of the debugging suggestions I got from the PHP site's manual is...
if($_GET){
//defining the session_id() before session_start() is the secret
session_id($_GET['session_id']);
session_start();
echo "Data: " . $_SESSION['theVar'];
//use your data before below commands
session_destroy();
session_commit();
}else{
//common session statement goes here
session_start();
$session_id=session_id();
$_SESSION['theVar'] = "theData";
echo "your.php?session_id=" . $session_id;
}
This was, accoring to the writer, guaranteed to work. It gives me...
1. On first access of page...
your.php?session_id=(session id)
session variable TheVar=TheData
...suggesting the ELSE clause above was run. A new tab was opened in order to display that. The page itself shows (correctly) a two-field (POST) form for Username and Password. There is no GET to trigger the first clause. I would have expected a GET given it's a primary condition of the protocol (GET logon.php).
2. Entering these I get...
your.php?session_id=(a different session id)
session variable TheVar=TheData
...which shows it took the same clause again. The page opens in another new tab. Form vars are submitted but still no querystring
3. Clicking the reload button I get the same as 2 but a different ID yet again.
4. Pressing Enter in the URL field of the browser gets me the same as 1 with yet another ID.
5. The successful form submission (2) shows a Log Off / End Session button. On clicking this I get a Form field from the button's Submission and a querystring from the button's Action (as designed). I get no session ID and no session variables, as expected (session vars are individually unset but I've also tried session_destroy()).
I've tried garbage collection and session_destroy (which work) but no further in.
The form itself, if relevant, is (leaving out divs, class etc)...
<form name="logonForm" action="/logon.php" method="POST">
Username: <input type="text" name="uid" value="" size="15" maxlength="30">
Password: <input type="password" name="pxman" value="" size="15" maxlength="30">
<input type="Submit" name="Logon" value="Logon">
Any help appreciated. It will save me going somewhat mental. :(