I am trying to create a user login with different sites for various users. The site selected is what's important as it determines what screen and options the user will see. A session variable is seemingly the best way to keep this site variable across all the pages. After reading php.net and posts and FAQs here, I'm still having difficulty getting the session variable to transfer. I think. I'm not even sure what it's doing. Here's the code that looks for the session variable, displays a page if it's not set which asks for the user name, password, and site, and then submits that form, checks the user name/password against the site selected and if correct, sets the $_SESSION variable. THEN, the page is supposed to navigate to the main page, which it doesn't. It goes back to the login page with $pwd=1. I left that part of the code out since it's quite large.
So, being a session newbie, but not really a PHP newbie, can someone point me in the direction of a fix? Doing this simply, I'm starting the session and then setting session variables, but the page is going back to the login page with pwd=1, which is very odd.
Thoughts? What am I doing wrong here? Thx,
DreamerZ
Code:
<?
session_start();
echo "<html><head><link rel='stylesheet' type='text/css' href='styles.css' />
<title>BST: Attendance Tracking System</title></head><body class=sheet>\n";
if($_SESSION['site'] == "")
{
echo "<form method=post name=frm_Pwd action='bstAbsence.phtml?pwd=1'>
<table border=0 width=100%><tr><td width=15%><img src='sbc_logo.gif'></td>
<td class=tablehead colspan=3>Billing Solutions Technology<BR>Supervisor's Toolkit</td></tr>\n
<tr><td colspan=4> </td></tr><tr><td> </td>\n
<td align=right class=emphasis width=25%>User: </td><td width=20%><input type=text name=user id=user></td>
<td> </td></tr><tr><td> </td>\n
<td class=emphasis align=right>Password: </td><td><input type=password name=userPWD id=userPWD></td></tr>\n
<tr><td colspan=4> </td></tr><tr><td colspan=2> </td><td>
<table border=1 width=100% bgcolor=lightblue class=emphasis><tr>
<td class=emphasis bgcolor=yellow colspan=2 align=center>Select a Site</td>\n
<input type=hidden name='siteNum' id='siteNum' value=0></tr>\n<tr><td width=15%>\n
<input type=radio name='siteSelect' id='siteSelect' value='BST' onChange='document.frm_Pwd.siteNum.value=1'></td>
<td>BST</td></tr>\n<tr><td width=15%>
<input type=radio name='siteSelect' id='siteSelect' value='RMT' onChange='document.frm_Pwd.siteNum.value=2'></td>\n
<td>RMT</td></tr></table></td></tr>\n<tr><tr><td colspan=4> </td></tr>\n
<tr><td align=center colspan=4><input type=button name=btn_Pwd value='Log In' onclick=login()></td></tr></table></form>\n
<script>
function login()
{
if(document.getElementById('user').value == '')
{
alert('Please enter your user name.');
document.getElementById('user').focus();
return false;
}
if(document.getElementById('userPWD').value == '')
{
alert('Please enter your password.');
document.getElementById('userPWD').focus();
return false;
}
if(document.frm_Pwd.siteNum.value == '0')
{
alert('Please select a SITE.');
document.getElementById('siteNum').focus();
return false;
}
document.frm_Pwd.submit()
}
</script></body></html>";
exit;
}
else { echo $_SESSION['site']; exit; }
if ($pwd == 1)
{
if ($siteNum == 1)
{
if ($user == 'BST' && $userPWD == 'BSTabs05')
{
$_SESSION['site'] = 'WestSac';
$pwd=0;
echo "<body onload=subLog()>
<form method=post action='[URL unfurl="true"]http://test2s.bst.sbc.com:8181/jfe/cm_test/toolkit/index.phtml'[/URL] name=frm_Log></form>
<script>function subLog() { document.frm_Log.submit(); }</script>";
}
}
else
{
if($user == 'RMT' && $userPWD == 'RMTabs05')
{
$_SESSION['site'] = 'Sac';
$pwd=0;
echo "<body onload=subLog()>
<form method=post action='[URL unfurl="true"]http://test2s.bst.sbc.com:8181/jfe/cm_test/ats/bstAbsence.phtml'[/URL] name=frm_Log></form>
<script>function subLog() { document.frm_Log.submit(); }</script>";
}
}
exit;
}
Thoughts? What am I doing wrong here? Thx,
DreamerZ