mjcoate Posted August 29, 2008 Share Posted August 29, 2008 I'm new to PHP/MySQL so this might be a really simple oversight on my part, I dont know. I'm trying to make a simple log-in page work. I've been using code from the PHP5/MySQL Bible and for the past 3 hours have been trying to make it work to no avail. Whenever I enter the username/password or for that matter simply leave the fields blank and hit the submit button, nothing happens. If the fields are blank, no error pops up like it should, if their correctly filled in nothing happens either. The page just sits there. WHATS UP WITH THIS?! If anyone could offer some help I would greatly appreciate it! Here is the code for the login page and the functions file: Login: <?PHP require_once('php/db_connect.php'); require_once('php/login_funcs.php'); //If logged in, log out if ($LOGGED_IN = user_isloggedin()) { user_logout(); $_COOKIE['user_name'] = ''; unset($LOGGED_IN); } if ($submit == 'Login') { if ( strlen($_POST['user_name']) <= 25 && strlen($_POST['password']) <= 25 ) { $feedback = user_login(); } else { $feedback = 'ERROR -- Username and password are too long'; } if ($feedback == 1) { //on successful login, redirect to homepage header('Location: http://www.organicgraceproject.org/4dm1n/4dm1n.php'); } else { $feedback_str = "<P class=\"errormess\">$feedback</P>"; } } else { $feedback_str = ''; } //-------------- //Form //-------------- $run_login = $_SERVER['PHP_SELF']; $login_form = <<< EOLOGINFORM $feedback//_str <form action="$run_login" method="post" > <table width="0%" border="0" cellspacing="0" cellpadding="3"> <tr> <td><span class="style10">Username</span></td> <td><label> <input type="text" name="user_name" id="user_name" size="25" maxlength"25"/> </label></td> </tr> <tr> <td><span class="style10">Password</span></td> <td><label> <input type="password" name="password" id="password" size="25" maxlength="25"/> </label></td> </tr> <tr> <td> </td> <td><div align="right"> <label> <input type="submit" name="Submit" id="Submit" value="Login" /> <br /> <a href="forgot_password.php"><span class="style10">Forgot password?</span></a> </label> </div></td> </tr> </table> </form> </div></td> </tr> </table></td> </tr> </table></td> </tr> </table> EOLOGINFORM; echo $login_form; ?> And heres the functions: <?php //Database variables file include_once('db_vars.php'); //MD5 string for encryption include_once('md5_hash.php'); $LOGGED_IN=false; unset($LOGGED_IN); function user_isloggedin() { //Only works with superglobal arrays. global $supersecret_hash_padding, $LOGGED_IN; //Already run hash checks? //If yes, return pre-set var if (isSet($LOGGED_IN)) { return $LOGGED_IN; } if ($_COOKIE['user_name'] && $_COOKIE['id_hash']) { $hash = md5($_COOKIE['user_name'] . $supersecret_hash_padding); if ($hash == $_COOKIE['id_hash']) { return true; } else { return false; } } else { return false; } } function user_login() { //Only works with superglobal arrays. if (!$_POST['user_name'] || !$_POST['password']) { $feedback = 'ERROR -- Missing username or password.'; return $feedback; } else { $user_name = strtolower($_POST['user_name']); $password = strtolower($_POST['password']); $crypt_pwd = md5($password); $query = "SELECT users FROM sysadmin_keswickusbible WHERE username = '$user_name' AND password = '$crypt_pwd'"; $result = mysql_query($query); if (!$result || mysql_num_rows($result) <1){ $feedback = 'ERROR -- User not found or passowrd incorret'; return $feedback; } else { } } } function user_logout() { setcookie('user_name', '', (time()+2592000), '/', '', 0); setcookie('id_hash', '', (time()+2592000), '/', '', 0); } function user_set_tokens($user_name_in) { global $supersecret_hash_padding; if (!$user_name_in) { $feedback = 'ERROR -- No username'; return false; } $user_name = strtolower($user_name_in); $id_hash = md5(user_name.$supersecret_hash_padding); setcookie('user_name', $user_name, (time()+2592000), '/', '', 0); setcookie('id_hash', $id_hash, (time()+2592000), '/', '', 0); } ?> Link to comment https://forums.phpfreaks.com/topic/121794-solved-help-im-going-nuts/ Share on other sites More sharing options...
akitchin Posted August 29, 2008 Share Posted August 29, 2008 the source of your woe: if ($submit == 'Login') { $submit won't technically exist if you don't have register_globals on (which you shouldn't). try changing that to: if ($_POST['submit'] == 'Login') { Link to comment https://forums.phpfreaks.com/topic/121794-solved-help-im-going-nuts/#findComment-628342 Share on other sites More sharing options...
mjcoate Posted August 29, 2008 Author Share Posted August 29, 2008 holy cow it works now! Thanks! Link to comment https://forums.phpfreaks.com/topic/121794-solved-help-im-going-nuts/#findComment-628349 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.