CodeMama Posted December 17, 2008 Share Posted December 17, 2008 Having problems getting my login form to work, Please help. index.php <?php include("inc/dbconn_open.php") ?> <?php $errs = error_reporting ('E_ALL'); if (isset($_POST['UserName'])) {$UserName = $_POST['UserName'];} else {$UserName = '';} if (isset($_POST['Password'])) {$Password = $_POST['Password'];} else {$Password = '';} $msg = ''; if (!empty($UserName)) { $sql = "SELECT * FROM admin WHERE UserName='$UserName' and Password='$Password'"; $result = mysql_query ($sql); $row = mysql_fetch_object ($result); If (mysql_num_rows($result) > 0) { $_SESSION['AdminLogin'] = $row->AdminID; header ("Location: Main.php"); } else { $msg = "Invalid Login"; } } ?> <HTML> <HEAD> <TITLE>Work Order System - Administrative Section</TITLE> <LINK REL="STYLESHEET" HREF="inc/style.css"> <script language="JavaScript"> <!-- function leftTrim(sString) { while (sString.substring(0,1) == ' ') { sString = sString.substring(1, sString.length); } return sString; } function chkData1(objForm) { objForm.UserName.value = leftTrim(objForm.UserName.value); if (objForm.UserName.value.length == 0) { alert("Please enter your User Name."); objForm.Email.focus(); return false; } objForm.Password.value = leftTrim(objForm.Password.value); if (objForm.Password.value.length == 0) { alert("Please enter a your Password."); objForm.Password.focus(); objForm.Password.select(); return false; } return true; } //--> </script> </HEAD> <BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0"> <TABLE WIDTH="750" BORDER="0" CELLSPACING="0" CELLPADDING="0"> <TR> <TD> </TD> </TR> <TR> <TD ALIGN="CENTER"><B>Work Order System - Administrative Section</B><BR><BR></TD> </TR> <TR> <TD> <?php If (!empty($msg)){ echo "<div class=\"cl_Error\">". $msg ."</div>"; } ?> <form name="form1" method="post" action="main.php?AdminID=<?php echo $AdminID; ?>" onSubmit="return chkData1(this)"> <TABLE WIDTH="300" BORDER="2" ALIGN="center" CELLPADDING="2" CELLSPACING="0" bordercolor="#000033" bgcolor="#0099CC"> <TR> <TD HEIGHT="22"><div class="admin_Main">Username:</div></TD> <TD HEIGHT="22"> <INPUT TYPE="text" NAME="UserName"></TD> </TR> <TR> <TD><div class="admin_Main">Password:</div></TD> <TD><INPUT TYPE="password" NAME="Password"></TD> </TR> <TR> <TD colspan="2" align="center"><INPUT TYPE="submit" VALUE="Login"> </TD> </TR> </TABLE> </form> </BODY> </HTML> Main.php [code]<?php include("inc/dbconn_open.php"); error_reporting ('E_ALL'); if (empty($_SESSION['AdminLogin']) OR $_SESSION['AdminLogin'] <> 'OK' ){ header ("Location: LogOut.php"); } if (isset($_SESSION['AdminID']) && !empty($_SESSION['AdminID'])){ $AdminID = $_SESSION['AdminID']; } else { header ("Location: LogOut.php"); } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Work Order System - Administrative Section</title> </head> <frameset cols="200,*" frameborder="NO" border="0" framespacing="0"> <frame src="Menu.php?AdminID=<?php echo $AdminID; ?>" name="leftFrame" scrolling="auto" noresize> <frame src="Welcome.php?AdminID=<?php echo $AdminID; ?>" name="mainFrame"> </frameset> <noframes><body> </body></noframes> </html> My session_start() is on the include db connection file.... Please need some clues...its not throwing errors on the page or in the error logs Thanks in advance [/code] Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/ Share on other sites More sharing options...
gevans Posted December 17, 2008 Share Posted December 17, 2008 It doesn't work... what's the problem?? Back to the same page? Always logged in? Any more details? Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-717997 Share on other sites More sharing options...
darkfreaks Posted December 17, 2008 Share Posted December 17, 2008 Cleaned up: <?php include("inc/dbconn_open.php") ?> <?php $errs = ini_set('error_reporting',E_ALL); if (isset($_POST['UserName'])) {$UserName = $_POST['UserName'];} else {$UserName = '';} if (isset($_POST['Password'])) {$Password = $_POST['Password'];} else {$Password = '';} $msg = ''; if (!empty($UserName)) { $sql = "SELECT * FROM admin WHERE UserName='$UserName' and Password='$Password'"; $result = mysql_query ($sql); $row = mysql_fetch_object ($result); If (mysql_num_rows($result) > 0) { $_SESSION['AdminLogin'] = $row->AdminID; header ("Location: Main.php"); } else { $msg = "Invalid Login"; } } ?> <HTML> <HEAD> <TITLE>Work Order System - Administrative Section</TITLE> <LINK REL="STYLESHEET" HREF="inc/style.css"> <script language="JavaScript"> <!-- function leftTrim(sString){ while(sString.substring(0,1)==' '){ sString=sString.substring(1,sString.length)} return sString} function chkData1(objForm){ objForm.UserName.value=leftTrim(objForm.UserName.value) if(objForm.UserName.value.length==0){ alert("Please enter your User Name.") objForm.Email.focus() return false} objForm.Password.value=leftTrim(objForm.Password.value) if(objForm.Password.value.length==0){ alert("Please enter a your Password.") objForm.Password.focus() objForm.Password.select() return false} return true} //--> </script> </HEAD> <BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0"> <TABLE WIDTH="750" BORDER="0" CELLSPACING="0" CELLPADDING="0"> <TR> <TD> </TD> </TR> <TR> <TD ALIGN="CENTER"><B>Work Order System - Administrative Section</B><BR><BR></TD> </TR> <TR> <TD> <?php If (!empty($msg)){ echo "<div class=\"cl_Error\">". $msg ."</div>"; } ?> <form name="form1" method="post" action="main.php?AdminID=<?php echo $AdminID; ?>" onSubmit="return chkData1(this)"> <TABLE WIDTH="300" BORDER="2" ALIGN="center" CELLPADDING="2" CELLSPACING="0" bordercolor="#000033" bgcolor="#0099CC"> <TR> <TD HEIGHT="22"><div class="admin_Main">Username:</div></TD> <TD HEIGHT="22"> <INPUT TYPE="text" NAME="UserName"></TD> </TR> <TR> <TD><div class="admin_Main">Password:</div></TD> <TD><INPUT TYPE="password" NAME="Password"></TD> </TR> <TR> <TD colspan="2" align="center"><INPUT TYPE="submit" VALUE="Login"> </TD> </TR> </TABLE> </form> </BODY> </HTML> Main.php [code]<?php include("inc/dbconn_open.php"); if (empty($_SESSION['AdminLogin']) || $_SESSION['AdminLogin'] <> 'OK' ){ header ("Location: LogOut.php"); exit; } if (isset($_SESSION['AdminID']) && !empty($_SESSION['AdminID'])){ $AdminID = $_SESSION['AdminID']; } else { header ("Location: LogOut.php"); exit; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Work Order System - Administrative Section</title> </head> <frameset cols="200,*" frameborder="NO" border="0" framespacing="0"> <frame src="Menu.php?AdminID=<?php echo $AdminID; ?>" name="leftFrame" scrolling="auto" noresize> <frame src="Welcome.php?AdminID=<?php echo $AdminID; ?>" name="mainFrame"> </frameset> <noframes><body> </body></noframes> </html> Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-718020 Share on other sites More sharing options...
CodeMama Posted December 30, 2008 Author Share Posted December 30, 2008 Hi guys, Ok I am still pulling my hair out on this, I did have it working but setting the $AdminID = "ok" and then it just logged in and passed OK in the url..but that will not work since certain users have certain admin fuctions pulled from the db according to that AdminID, so when it got to those pages it was just looking at the db for adminID with OK to load the functions....I have tried to store as a variable, I'm really stuck and just keep making it worse I think... Here are the two scripts, someone please show me how I take the AdminID from page to page throughout this application , I am not declaring or "setting" it right....I'm so tired! Index.php <?php session_start(); //start session include("inc/dbconn_open.php") ; //connect to the db if (isset($_POST['UserName'])) {$UserName = $_POST['UserName'];} else {$UserName = '';}//user if (isset($_POST['Password'])) {$Password = $_POST['Password'];} else {$Password = '';}//password $msg = ' Please enter your Username and Password'; if (!empty($UserName)) { $sql = "SELECT * FROM admin WHERE UserName='$UserName' and Password='$Password'"; $result = mysql_query ($sql); $row = mysql_fetch_object ($result); If (mysql_num_rows($result) > 0) { $_SESSION['AdminLogin'] = $row->AdminID; header ("Location: Main.php"); } else { $msg = "Invalid Login"; } } ?> which is supposed to pass to main.php <?php session_start(); include("inc/dbconn_open.php"); if (empty($_SESSION['AdminLogin']) OR $_SESSION['AdminLogin'] <> 'YES' ){ header ("Location: LogOut.php"); } //if (isset($_GET['AdminID']) && !empty($_GET['AdminID'])){ //} // else { //header ("Location: LogOut.php"); //} ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Work Order System - Administrative Section</title> </head> <frameset cols="200,*" frameborder="NO" border="0" framespacing="0"> <frame src="Menu.php?AdminID=<?php echo $_SESSION['AdminLogin']; ?>" name="leftFrame" scrolling="auto" noresize> <frame src="Welcome.php?AdminID=<?php echo $_SESSION['AdminLogin']; ?>" name="mainFrame"> </frameset> <noframes><body> </body></noframes> </html> Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726532 Share on other sites More sharing options...
darkfreaks Posted December 30, 2008 Share Posted December 30, 2008 im not one for OOP but is Admin id a function and not a variable im confused ??? Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726542 Share on other sites More sharing options...
CodeMama Posted December 30, 2008 Author Share Posted December 30, 2008 Thanks for looking, AdminID is an ID stored in a db, the users are given one when their acct is set up, and it stores what they can and cannot do in the system. I made a couple changes, just re-read the O'reilly chapter on Sessions but I still stuck ... blah... so now in index.php I am trying to registers the login, so I can SUPPOSEDLY use it later that is where i"m stuck its not getting used to open the next page... index.php <?php session_start(); //start session session_register('AdminID'); session_register('UserName'); session_register('Password'); include("inc/dbconn_open.php") ; //connect to the db if (isset($_POST['UserName'])) {$UserName = $_POST['UserName'];} else {$UserName = '';}//user if (isset($_POST['Password'])) {$Password = $_POST['Password'];} else {$Password = '';}//password $msg = ' Please enter your Username and Password'; if (!empty($UserName)) { $sql = "SELECT * FROM admin WHERE UserName='$UserName' and Password='$Password'"; $result = mysql_query ($sql); $row = mysql_fetch_object ($result); If (mysql_num_rows($result) > 0) { $_SESSION['AdminLogin'] = $row->$AdminID; header ("Location: Main.php"); } else { $msg = "Invalid Login"; } } ?> Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726548 Share on other sites More sharing options...
revraz Posted December 30, 2008 Share Posted December 30, 2008 You don't need session_register when you use session_start(). Just use the session array $_SESSION['AdminID'] etc.. Do you have error display and reporting turned on? Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726553 Share on other sites More sharing options...
darkfreaks Posted December 30, 2008 Share Posted December 30, 2008 <?php class admin{ function register_admin() { $sql = "SELECT * FROM admin WHERE UserName='$UserName' and Password='$Password'"; $result = mysql_query ($sql); $row = mysql_fetch_object ($result); If (mysql_num_rows($result) > 0) { $result= $_SESSION['AdminLogin'] = $row->$AdminID;} return $result; } } $call_result= new admin; echo $call_result->register_admin(); ?> Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726560 Share on other sites More sharing options...
CodeMama Posted December 30, 2008 Author Share Posted December 30, 2008 Thanks for looking guys, ok I do have my error reporting on I just put the error_reporting(E_All); back in my code from above. I have made progress in that, now when I login it does go to the main.php yet does not load the menus to go with the AdminID its just a blank page. the code now is : index.php <?php error_reporting(E_ALL); session_start(); //start session session_register('AdminID'); session_register('UserName'); session_register('Password'); include("inc/dbconn_open.php") ; //connect to the db if (isset($_POST['UserName'])) {$UserName = $_POST['UserName'];} else {$UserName = '';}//user if (isset($_POST['Password'])) {$Password = $_POST['Password'];} else {$Password = '';}//password $msg = ' Please enter your Username and Password'; if (!empty($UserName)) { $sql = "SELECT * FROM admin WHERE UserName='$UserName' and Password='$Password'"; $result = mysql_query ($sql); $row = mysql_fetch_object ($result); If (mysql_num_rows($result) > 0) { $_SESSION['AdminID'] = $row->$AdminID; header ("Location: Main.php"); } else { $msg = "Invalid Login"; } } ?> and the main.php <?php session_start(); include("inc/dbconn_open.php"); if (empty($_SESSION['AdminID']) OR $_SESSION['AdminID'] <> 'YES' ){ header ("Location: LogOut.php"); } if (isset($_GET['AdminID']) && !empty($_GET['AdminID'])){ } else { header ("Location: LogOut.php"); } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Work Order System - Administrative Section</title> </head> <frameset cols="200,*" frameborder="NO" border="0" framespacing="0"> <frame src="Menu.php?AdminID=<?php echo $_SESSION['AdminID']; ?>" name="leftFrame" scrolling="auto" noresize> <frame src="Welcome.php?AdminID=<?php echo $_SESSION['AdminID']; ?>" name="mainFrame"> </frameset> And you will see above how it was passing in the URL and that is what I DON"T WANT but can't figure out how to make it work Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726568 Share on other sites More sharing options...
darkfreaks Posted December 30, 2008 Share Posted December 30, 2008 have you tried modding in my admin OOP class to call on the pages ??? Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726569 Share on other sites More sharing options...
darkfreaks Posted December 30, 2008 Share Posted December 30, 2008 Passing sessions with session_id and cookies: http://dev.fyicenter.com/faq/php/php_using_sessions_2.php Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726575 Share on other sites More sharing options...
CodeMama Posted December 30, 2008 Author Share Posted December 30, 2008 it's going to be my next step , I figured if I can't get what should be a simple session to go from page to page, surely OOP classes are going to confuse me ever worse. but here I go... its got to be something with the way i'm trying to use the session $adminID on the other pages. thanks freak for trying to help me none the less! Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726576 Share on other sites More sharing options...
darkfreaks Posted December 30, 2008 Share Posted December 30, 2008 its really not that hard to get its just a class that gets the admin if its greater than 0. and returns it so all you have to do is call <?php echo $call_result->register_admin();?> instead of <?php echo $_SESSION['Adminid'];?> where your passing it thru the url Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726581 Share on other sites More sharing options...
CodeMama Posted December 30, 2008 Author Share Posted December 30, 2008 Well it returns nothing..nothing prints to the page, (I just did the tutorial you sent me to ) tried to get the page to write the SID ...nada... Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726586 Share on other sites More sharing options...
darkfreaks Posted December 30, 2008 Share Posted December 30, 2008 did you try adding session_start() to the class ??? <?php class admin{ function register_admin() { session_start(); //start session session_register('AdminID'); session_register('UserName'); session_register('Password'); $sql = "SELECT * FROM admin WHERE UserName='$UserName' and Password='$Password'"; $result = mysql_query ($sql); $row = mysql_fetch_object ($result); If (mysql_num_rows($result) > 0) { $result= $_SESSION['AdminLogin'] = $row->$AdminID;} return $result; } } $call_result= new admin; echo $call_result->register_admin(); ?> Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726591 Share on other sites More sharing options...
CodeMama Posted December 30, 2008 Author Share Posted December 30, 2008 maybe the AdminID is not defined right, it's a field in the db, I need that number so the page knows what menu items to load... Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726593 Share on other sites More sharing options...
darkfreaks Posted December 30, 2008 Share Posted December 30, 2008 yeah that is your problem you need to tell it what to load like <?php if($AdminID=="OK") { //load menu here } else { //do this }?> Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-726602 Share on other sites More sharing options...
CodeMama Posted December 31, 2008 Author Share Posted December 31, 2008 Still stuck, it only works if its passing something in the URL for me, I am just not getting it and anytime I try to use this $result= $_SESSION['AdminLogin'] = $row->$AdminID;} I get a blank page. Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-727205 Share on other sites More sharing options...
CodeMama Posted December 31, 2008 Author Share Posted December 31, 2008 Oh and Currently the code is this, and this would work if I could define AdminID as the to use later if I echo AdminID is just saying its OK So when I try to pull something from the db according to the AdminID I of course get nothing because there are none in the db that are OK they are actual ID's.... My crappy code <?php session_start(); error_reporting(E_ALL); include("inc/dbconn_open.php") ; if (isset($_POST['UserName'])) {$UserName = $_POST['UserName'];} else {$UserName = '';} if (isset($_POST['Password'])) {$Password = $_POST['Password'];} else {$Password = '';} $msg = ''; if (!empty($UserName)) { $sql = "SELECT * FROM admin WHERE UserName='$UserName' and Password='$Password'"; $result = mysql_query ($sql); $row = mysql_fetch_object ($result); If (mysql_num_rows($result) > 0) { $_SESSION['AdminLogin'] = 'OK'; header ("Location: Main.php?AdminID=". $_SESSION['AdminLogin']); } else { $msg = "Sorry You Entered An Invalid Login"; } } ?> Passes to Main.php <?php session_start(); error_reporting(E_ALL); include("inc/dbconn_open.php"); if (empty($_SESSION['AdminLogin']) OR $_SESSION['AdminLogin'] <> 'OK' ){ header ("Location: LogOut.php"); } if (isset($_GET['AdminID']) && !empty($_GET['AdminID'])){ $AdminID = $_GET['AdminID']; } else { header ("Location: LogOut.php"); } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Work Order System - Administrative Section</title> </head> <frameset cols="200,*" frameborder="NO" border="0" framespacing="0"> <frame src="Menu.php?AdminID=<?php echo $_SESSION['AdminLogin']; ?>" name="leftFrame" scrolling="auto" noresize> <frame src="Welcome.php?AdminID=<?php echo $_SESSION['AdminLogin']; ?>" name="mainFrame"> </frameset> <noframes><body> </body></noframes> </html> Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-727208 Share on other sites More sharing options...
darkfreaks Posted December 31, 2008 Share Posted December 31, 2008 first off try using single quotes on your headers so you can parse the session right through the header. <?php header ('Location: Main.php?AdminID='. $_SESSION['AdminLogin'].'');?> Link to comment https://forums.phpfreaks.com/topic/137409-solved-login-and-sessions-form-help/#findComment-727256 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.