Search the Community
Showing results for tags 'login php script'.
-
Hi, Currently having an issue with php login script. The login script works fine and logs in the correct user, but the problem is, is that any link I click regardless whether it is the log out button, it seems to end the session and logs me back out again. Total newbie to php, can I have some help please? Also, is there a way to display the users' name from the user table inside the echo "you logged in as", I can only seem to get the ID? Thank you for your help. Login form (in page header): <div class="loginform"> <?php if ($_SESSION['id'] > 0){ echo "You are logged in as"; ?> <?php print $GLOBALS['user']->name; ?> <a href="logout.php">Logout</a> <?php }else{ echo "<p>Login:</p>\n"; ?> <form name="loginform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <b>Username:</b> <input type="text" name="liusername"> <b>Password:</b> <input type="password" name="lipassword"> <input type="submit" name="lisubmit" value="Login"> </form> </div> PHP authenticate (in page top) <?php if (isset($_POST['lisubmit'])); $query = "SELECT user_id, user_password FROM user WHERE user_username = '".$_POST['liusername']."'"; $result = mysql_query($query) or die (mysql_error()); $row = mysql_fetch_array($result); if ($row['user_password'] == $_POST['lipassword']){ $_SESSION['loggedin'] = true; $_SESSION['id'] = $row['user_id']; }else{ $_SESSION['loggedin'] = false; $_SESSION['id'] = 0; } ?>