Greetings everyone! Hope this message finds everyone well?
Anyhow, I've recently stumbled upon a strange problem here in my code. I'm wondering if anyone can help me find what I'm doing wrong. What I'm trying to do is to POST (via standard html forms) a variable to display some text (to expand options under a category heading), then in the expanded options, a form is displayed. On submitting the form, program flows to adminprocess.php, where processing of the form information takes place. After the processing is complete, $_SESSION['adminSection'] is set to the name of the section which had been expanded in the previous forms page. This is so that we can display the expanded options on returning from the adminprocess.php, to keep from confusing the users when we have an error on the submitted form we need to display.
HOWEVER, it doesn't seem to want to display for me. What I mean by that is that upon RETURNING to adminPage.php, although my $_SESSION['adminSection'] variable is set to 'adminUserFuncs' (shown through echo tests), it WILL NOT show the expanded options, as though the variable isn't set, or the basic if() test isn't being properly set up. Can anyone tell me what I'm doing wrong here? I'm running PHP 5.0 and Apache 2.0.55. Thanks for your help in advance!
<<<From adminPage.php (the forms page)>>>
if(!isset($_POST['viewUserFuncs'])) {
echo 'random arbitrary text!';
echo '<form method="POST" action="adminPage.php">';
echo '<input type="submit" name="viewUserFuncs" value="Expand Options" class="buttonFont">';
echo '</form><br />';
} elseif(isset($_POST['viewUserFuncs']) || ($_SESSION['adminSection'] == 'adminUserFuncs')) {
echo '<form method="POST" action="adminprocess.php">';
echo 'form here prompting for, say, adding a new user</form>';
}
I have also tried a couple variations of this logic, to no avail. It's almost as if there's a subtle nuance of PHP $_POST and $_SESSION variables that I'm not understanding. Here's an example variation:
<<<Variation Example of above code>>>
if(!isset($_POST['viewUserFuncs']) || ($_SESSION['adminSection'] !== 'adminUserFuncs')) {
echo 'random arbitrary text!';
echo '<form method="POST" action="adminPage.php">';
echo '<input type="submit" name="viewUserFuncs" value="Expand Options" class="buttonFont">';
echo '</form><br />';
} else {
echo '<form method="POST" action="adminprocess.php">';
echo 'form here prompting for, say, adding a new user</form>';
}
<<<From adminprocess.php (the processing page)>>>
function ArbitraryCodeAndFunctions() {
if(!preg_match("/^[A-Za-z0-9_\.\-]+@[A-Za-z0-9\.\-]+\.[A-Za-z]+$/", $email)) {
$errorMsg = "You must enter a valid email address.";
$adminSection = "adminAddUser";
$this->adminAddUserInfo($errorMsg, $adminSection);
}
<<<From further down in adminprocess.php (where it sets session vars)>>>
function adminAddUserInfo($errorMsg, $adminSection) {
$_SESSION['adminSection'] = "adminUserFuncs";
$_SESSION['error'] = $errorMsg;
$_SESSION['errorForWho'] = $adminSection;
$_SESSION['errorCount'] = '1';
$referrer = $_SESSION['lastPage'];
header("Location: $referrer");
exit;
}