Post / Session Issue

Hello,

I’m having the following Issue and I cannot figure out for the life of me after about a week of stuggling.

I have a log in page, which posts a Name, UserName, Password and a securityid. It seems like everything posts fine right when you log in. But for some reason my “SecurityID” session doesnt carry over to anything, but everything else does. Since the logic has to include the securityID , I have to get this fixed.

Any help pointing out my issue would be greatly appriciated. I’ve been trying to figure this issue out over a week.

Begin Login Page


[php]<?php
$a = session_id();
if(empty($a))
{
session_start();
}

$CustomerID = 0;
$FirstName = “”;
$LastName = “”;
$UserName = “”;
$Password = “”;
$SecurityID = 0;
include “MySQLConnector.txt”;

// Get the data from the form:
/// Original Logic
//$UserName = $_REQUEST[‘UserName’];
//$Password = $_REQUEST[‘Password’];

$UserName = (isset($_POST[‘UserName’])) ? $_POST[‘UserName’] : FALSE;
$Password = (isset($_POST[‘Password’])) ? $_POST[‘Password’] : FALSE;

//echo "Customer ID : $CustomerID
";
//echo "FirstName : $FirstName
";
//echo "UserName : $UserName
";
//echo "Password : $Password
";

$query = “SELECT CustomerID, FirstName, LastName, SecurityID FROM Customers
WHERE UserName= '” . $UserName . “’ AND Password= '” . $Password . "’ "; // Build the query
$rs = @mysqli_query($dbc, $query); // Return the Result Set
while($row = mysqli_fetch_array($rs, MYSQLI_ASSOC))// Fetch the data
{
$CustomerID = $row[‘CustomerID’];
$FirstName = $row[‘FirstName’];
$LastName = $row[‘LastName’];
$SecurityID = $row[‘SecurityID’];
}

//echo "Here’s the Query: $query
";
//echo "CustomerID : " . $_SESSION[‘CustomerID’];
//echo "UserName : " . $_SESSION[‘UserName’];
//echo "Password : " . $_SESSION[‘Password’];
//echo "SecurityID : " . $_SESSION[‘SecurityID’];
//echo "FirstName: " . $_SESSION[‘FirstName’];

mysqli_query($dbc, $query);

if ($CustomerID != 0)
{
$_SESSION[‘CustomerID’] = $CustomerID;
$_SESSION[‘FirstName’] = $FirstName;
$_SESSION[‘LastName’] = $LastName;
$_SESSION[‘SecurityID’] = $SecurityID;
$_SESSION[‘UserName’] = $UserName;
$_SESSION[‘Password’] = $Password;
//$SecurityID = (isset($_POST[‘SecurityID’])) ? $_POST[‘SecurityID’] : FALSE;
}
else
{
echo “Student Not Found”;
}

echo "CustomerID : " . $_SESSION[‘CustomerID’];
//echo "UserName : " . $_SESSION[‘UserName’];
//echo "Password : " . $_SESSION[‘Password’];
echo "SecurityID : " . $_SESSION[‘SecurityID’];
//echo "FirstName: " . $_SESSION[‘FirstName’];

if (isset($_GET[‘SecurityID’]))
{
$SecurityID = $_POST[‘SecurityID’];
}
else
{
$SecurityID = 0;
}

mysqli_close($dbc);

//header(“Location: index.php”); //Comment This Line to Debug
?>[/php]


Begin My Side Page — **** This always seems to keep every thing but the security ID
and I have extra menues that need to show, which they arent retaining because I lose the ID


[code]


<?php
$a = session_id();
if (empty($a))
session_start();
if (isset($_GET['SecurityID'])) {
    $SecurityID = $_GET['SecurityID'];
} else {
    $SecurityID = 0;
}

if (isset($_GET['menukey'])) {
    $menukey = $_GET['menukey'];
} else {
    $menukey = 0;
}
switch ($menukey) {
    case 1:
        include "primarycontent.php";
        break;
    case 2:
        include "CustomerData.php";
        break;
    // include "enterdata.php" was the original page
    case 22:
        include "InsertCustomer.php";
        break;
    // include "insert.php";   was the original page.
    case 222:
        if (isset($_REQUEST['action'])) {
            include "advancedsearchpost.php";
        } else {
            include "advancedsearch.php";
        }
        break;
    case 3:
        if (isset($_GET['DeleteCustomerID'])) {
            $_SESSION['DeleteCustomerID'] = $_GET['DeleteCustomerID'];
        } else {
            $_SESSION['DeleteCustomerID'] = 0;
        }

        include "DeleteConfirm.php";
        break;
    case 33:
        include "delete.php";
        break;
    case 4:
        include "login.php";
        break;
    case 44:
        include "logoff.php";
        break;
    case 6:
        include "maintain.php";
        break;
    case 66:
        $_SESSION['KeywordSearchWhereClause'] = "";
        include "maintain.php";
        break;

    case 7:
        $_SESSION['MajorChange'] = 0;
        $_SESSION['CustomerID2Update'] = 0;
        include "CustomerPreferences.php";
        //include "enterpreferences.php";
        break;
    case 77:
        if (isset($_REQUEST['action'])) {
            $_SESSION['MajorChange'] = 0;
            include "insertpreferences.php";
        } else {
            $_SESSION['MajorChange'] = 1;
            include "enterpreferences.php";
        }
        break;

    case 8:
        include "";
        break;


        //default:   // case else
        include "primarycontent.php";
        break;
}
?>   

<div class="login">
    <?php
    if ($_SESSION['CustomerID'] == 0) {
        echo '<form method="post" action="index.php?menukey=4">
                             <div>
                                <span>UserName:</span><input type="text" class="text" maxlength="32" name="UserName" />
                                <span>Password:</span><input type="Password" class="text" maxlength="32" name="Password" />
                                <input type="submit" class="button" value="Login" /><br>
                                <span>New customer? </span><a href="CustomerData.php">Start here...</a>
                             </div>
                             </form>';
    } else {

        echo 'Customer ID = ' . $_SESSION['CustomerID'] . '<br>';
        //echo 'Welcome ' . $_SESSION['FirstName'] . '<br>';
        //echo 'Welcome ' . $_SESSION['LastName'] . '<br>';
        echo 'Welcome ' . $_SESSION['FirstName'] . ' ' . $_SESSION['LastName'] . '<br>';
        echo 'Security ID: ' . $_SESSION['SecurityID'] . '<br>';
        echo '<a href="index.php?menukey=44">Logoff</a>';
    }
    ?>
</div><!-- end login -->

<div class="box">
    <ul>
        <li><a href="index.php?menukey=222">Advanced Search</a></li>
        <?php if ($_SESSION['SecurityID'] == 1) {   // Logged In         ?>
            <li><a href="CustomerData.php">My Account</a></li>
            <li><a href="index.php?menukey=7">My Preferences</a></li>


        <?php }
        if ($_SESSION['SecurityID'] == 2) {   // Administrator      
            ?>
            <li><a href="CustomerData.php">My Account</a></li>
            <li><a href="maintain.php">Maintain all records</a></li>
            <li><a href="index.php?menukey=7">My Preferences</a></li>
            <li><a href="index.php?menukey=222">Advanced Search</a></li>

            <form action="maintain.php" method="post" name="KeywordSearchPost">
                <input type="text" name="txtKeywordSearch" size="14" maxlength="20" style="font-size: 8pt">
                <input type="submit" class="button" value="Search" />
            </form>
        <?php
        }
        //header("Location: index.php");   //Comment This Line to Debug         
        ?>

        <li><a href="http://itd1.cincinnatistate.edu/abank/answerbank/" target=_blank>CIT Answer Bank</a></li>
    </ul>
</div><!-- end box -->
[/code]

Should session_start be the first thing I had this before Where I could not login because session start was started after the php code had already started.
I had to move the session_start to the very top, as I cannot see where you start your session or do you have session.auto_start = 1 in your php ?.

Well,

I found my issue, it wasnt that. I had a sub page that I had a typo on that was kiling my security ID… After fighting that for several days. Arggg…

Sponsor our Newsletter | Privacy Policy | Terms of Service