Xzalious Posted June 27, 2008 Share Posted June 27, 2008 Alright, here are my 2 problems, hope someone on here can possibly help me with them: Problem #1: When i enter my site, every things fine, i enter my details i click Login and thats where it all goes wrong, i end up with the same page, no error even though i have error variables all over my code to tell me if something went wrong, my form is blank and it hasn't taken me to members.php Problem #2: With members.php, when it loads i can't seem to get information from the "time_old" field in my table, what i want to do is to write to "time_new" when a person logs in so that it keeps the time they logged in, and when they logout to transfer the value in "Time_new" to "time_old" so that when the user first enters members.php it says "Hello, Xzalious(working)" then on a new line it says "You last logged in at 0:00am(failsafe)" What i would like someone to do would be to cruise through my code see if there is anything terribly wrong with it, or edit my code to include a way to tell the user when he/she last logged in. That would be awesome, thanks to anyone that helps. login.php's code: <?php require_once('lib/settings.php'); error_reporting(E_ALL); ini_set('display_errors', 'on'); $maintenance = 0; if ( array_key_exists ( '_submit_check', $_POST ) ) { if ( $maintenance == 0 ) { if ( $_POST['username'] != '' && $_POST['password'] != '' ) { $query = 'SELECT ID, Username, Active, Password FROM ' . DBPREFIX . 'users WHERE Username = ' . $db->qstr ( $_POST['username'] ) . ' AND Password = ' . $db->qstr ( md5 ( $_POST['password'] ) ); if ( $db->RecordCount ( $query ) == 1 ) { $row = $db->getRow ( $query ); if ( $row->Active == 1 ) { // Call the function to start the session with our login details set_login_sessions ( $row->ID, $row->Password, ( $_POST['remember'] ) ? TRUE : FALSE ); // Calculate Australian time to be entered into the database $hourdiff = "14"; $datenow = date("l jS \of F Y",time() + ($hourdiff * 3600)); $timenow = date("g:i A",time() + ($hourdiff * 3600)); //Update the time and date of the login $update = ('UPDATE users SET Date_new = '.$datenow.', Time_new = '.$timenow.' WHERE users.username = '.$db->qstr ( $_POST['username'] )); if ( ! $db->query ($update)) { $error = 'Failed to update Time and Date'; } header ( "Location: members.php"); } elseif ( $row->Active == 0 ) { $error = 'Your membership was not activated. Please open the activation link in the email we sent.'; } elseif ( $row->Active == 2 ) { $error = 'You are suspended!'; } } else { $error = 'Login failed!'; } } else { $error = 'Please use both your username and password to access your account'; } } else { $error = 'The database is currently under maintenance, please wait before attempting to login again'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Xzaliouses Database - Login</title> <link href="css/databasev3.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="container"> <div id="box"> <div id="header"> </div> <?php if ( isset($error)): ?> <div id="error"> <table> <tr> <td width="10"></td> <td width="520"> <?php echo $error ?></td> </tr> </table> </div> <div id="spacer"> <!-- nothing !--> </div> <?php endif; ?> <div id="login"> <form class="form" action="<?=$_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr> <td width="58"></td> <td width="200"> <input type="hidden" name="_submit_check" value="1"/> Username: <br /> <input class="input" type="text" name="username" id="username" size="25" maxlength="40" value="" /> <br /> Password: <br /> <input class="input" type="password" name="password" id="password" size="25" maxlength="32" /> </td> <td width="75"> <input name="Loginimg" type="image" src="images/Login.png" title="submit" value="Login" alt="submit" /><br /></td> <td width="196"> <input name="Login" type="image" src="images/logintext.png" value="Login" /><br />Access the database to interact with features, settings and users.</td> </tr> </table> </form> </div> <div id="footer"> <center>© Xzalious 2008</center> </div> </div> </div> </body> </html> members.php's code <?php require_once('lib/settings.php'); checkLogin('1 2'); error_reporting(E_ALL); ini_set('display_errors', 'on'); $user = get_username ( $_SESSION['user_id'] ); $messages = "0"; //$gettimedate = ('SELECT `Time`, `Date`, `Username` FROM `users` WHERE `Username` = '.$user.""); //if ( $db->RecordCount ( $gettimedate ) == 1 ) { // $lastlogin = $db->getRow ( $gettimedate ); // $time = $lastlogin->Time; // $date = $lastlogin->Date; //} else { // $time = "0:00am"; // $date = "Sunday, 0th of January, 0000"; //} $time = "0"; $date = "0"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>xzaliouses Database - Members</title> <link href="css/databasev3.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="container"> <div id="box"> <div id="header"> </div> <div id="user"> <table border="0"> <tr> <td width="125"> <img src="images/noavatar.jpg" name="avatar" id="avatar" /><br /> </td> <td width="412"> Hello, <? echo $user ?>.<br /><br /> You have <? echo $messages ?> messages in your inbox.<br /> Your last login was <? echo $time." on ".$date ?> </td> </tr> </table> </div> <div id="spacer"> <!-- nothing !--> </div> <div id="content"> <table style="margin-left:25px;" width="500" border="0"> <tr> <td width="500">You are here: /<a href="members.php">members</a>/</td> </tr> </table> <table style="margin-left:25px;margin-top:10px;" width="500" border="0"> <tr> <td width="75" height="80"><img src="images/inbox.png" width="72" height="72" /></td> <td width="175" height="80"><p><span class="tablelink"><a href="inbox.php">Inbox</a></span><br />Access your inbox to read, compose and delete mail.</p></td> <td width="75" height="80"><img src="images/avatar.png" width="72" height="72" /></td> <td width="175" height="80"><span class="tablelink"><a href="avatar.php">Avatar</a></span><br />Change your avatar settings for the database.</td> </tr> <tr> <td width="75" height="80"><img src="images/controlpanel.png" width="72" height="72" /></td> <td width="175" height="80"><a href="usercp.php" class="tablelink">Control Panel</a><br />Change your database settings for this site and it's pages.</td> <td width="75" height="80"><img src="images/profile.png" width="72" height="72" /></td> <td width="175" height="80"><a href="profile.php"><span class="tablelink">Profile</span></a><br />Change your profile details that other members can see.</td> </tr> <tr> <td width="75" height="80"><img src="images/members.png" width="72" height="72" /></td> <td width="175" height="80"><a href="members.php" class="tablelink">Members</a><br />Search through the public member list and profiles.</td> <td width="75" height="80"><img src="images/settings.png" width="72" height="72" /></td> <td width="175" height="80"><a href="datacp.php" class="tablelink">Database Settings</a><br />Configure how you use the database and its features.</td> </tr> <tr> <td width="75" height="80"><img src="images/help.png" width="72" height="72" /></td> <td width="175" height="80"><a href="help.php" class="tablelink">Help</a><br />Get help using the database with FAQs or submit a ticket.</td> <td width="75" height="80"><img src="images/logout.png" width="72" height="72" /></td> <td width="175" height="80"><a href="logout.php" class="tablelink">Logout</a><br />Sign out of the database and end your session.</td> </tr> <tr> <td width="75" height="80"><img src="images/affiliates.png" width="72" height="72" /></td> <td width="175" height="80"><a href="affiliates.php" class="tablelink">Affiliates</a><br />Links to places who helped make the database.</td> <td width="75" height="80"><img src="images/about.png" width="72" height="72" /></td> <td width="175" height="80"><a href="about.php" class="tablelink">About</a><br />All about Xzalious, his profile is also on this page for viewing.</td> </tr> </table> </div> <div id="footer"> <center>© Xzalious 2008</center> </div> </div> </div> </body> </html> set_login_sessions function: function set_login_sessions ( $user_id, $password, $remember ) { //start the session session_start(); //set the sessions $_SESSION['user_id'] = $user_id; $_SESSION['logged_in'] = TRUE; //do we have "remember me"? if ( $remember ) { setcookie ( "cookie_id", $user_id, time() + KEEP_LOGGED_IN_FOR, COOKIE_PATH ); setcookie ( "authenticate", md5 ( getIP () . $password . $_SERVER['USER_AGENT'] ), time() + KEEP_LOGGED_IN_FOR, COOKIE_PATH ); } } $db->getRow,query,RecordCount etc. are all parts of a functions.php file that makes connecting with mysql easier, i'm pretty sure all there functions etc work, i just don't know if i'm using them properly, if need be i'll post it 'cause it's pretty long and i don't want to clutter this first post. Link to comment https://forums.phpfreaks.com/topic/112185-login-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.