jepperask Posted November 8, 2012 Share Posted November 8, 2012 (edited) Hi guys - I've had problems with this for a couple of hours now, so now im asking you! ;-) I'm creating a blog, where i can log in in the header.php file (which i include on all the pages, as a sticky "move-around" -toolbar. But I would like the form to be removed when I am logged in, and instead have a log out button and preferences (or just to be removed as a start). I've tried to solve it by adding !$_session['user_id']{*FORM-CODE-WITH-INPUT-AREA-HERE}; meaning, that if the user is logged in, the above thing wont even come up. But i couldn't really make it work. Heres my code: <?php session_start(); if(isset($_POST['submit'])) { $user = $_POST['username']; $pwrd = $_POST['pwrd']; //include database connection include 'db_connect.php'; if(empty($user) || empty($pwrd)){ echo("Missing Information"); }else{ $user = strip_tags($user); $user = $db->real_escape_string($user); $pwrd = strip_tags($pwrd); $pwrd = $db->real_escape_string($pwrd); $pwrd = md5($pwrd); $query = $db->query("SELECT user_id, username FROM user WHERE username='$user' AND password='$pwrd'"); if($query->num_rows == 1){ while($row = $query->fetch_object()){ $_SESSION['user_id'] = $row->user_id; } header('Location: admin-page.php'); exit(); }else{ echo "Missing Information!"; } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script src="http://code.jquery.com/jquery-1.5.min.js"></script> </head> <body> <div id="container"> <form action="login.php" method="post"> <p> <label>Username</label><input type="text" name="username"> <label>Password</label><input type="password" name="pwrd"> <input type="submit" name="submit" value="LogIn"> </p> </form> </div> </body> </html> And the code is by the way just the login.php, which i already included in the header.php. Edited November 8, 2012 by jepperask Quote Link to comment https://forums.phpfreaks.com/topic/270477-remove-form-when-its-been-used/ Share on other sites More sharing options...
akphidelt2007 Posted November 8, 2012 Share Posted November 8, 2012 (edited) Stick it in your html... <?php if(isset($_SESSION['user_id'])) { ?> Welcome | Log Out <?php } else { ?> <form action="login.php" method="post"> <p> <label>Username</label><input type="text" name="username"> <label>Password</label><input type="password" name="pwrd"> <input type="submit" name="submit" value="LogIn"> </p> </form> <?php } ?> That's just quick and dirty but hopefully you get the drift. Edited November 8, 2012 by akphidelt2007 Quote Link to comment https://forums.phpfreaks.com/topic/270477-remove-form-when-its-been-used/#findComment-1391183 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.