mccrum Posted April 28, 2009 Share Posted April 28, 2009 I made a simple PHP login form that uses only 1 username and password to login. If I currently type in the correct username and password it displays "LOGIN SUCCESSFUL" and shows a link to the admin page but I would like to include the admin page within the php file. Below is the code I have used, hope you can help. <!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" dir="ltr" lang="en-US"> <head> <title>Energy Saving › Admin Log In</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel='stylesheet' href='login.css' type='text/css' media='all' /> </head> <div class="container"> <div id="header"></div> <body class="login"> <div id="login"> <h1><a href="login.html">Energy Saving Logo</a></h1> <?php $loginname = "admin"; $loginpassword = "password"; if ($_POST['text'] != $loginname || $_POST['password'] != $loginpassword) { ?> <div id="login_error"> <strong>ERROR</strong>: Incorrect Username or Password.<br /></div> <?php } else { ?> <div id="login_sucess"> <strong>LOGIN SUCCESSFUL</strong>: <a href="login.html">Click here</a> to continue.</div> <?php } ?> <form name="login" id="loginform" action="login.php" method="post"> <p> <label>Username:<br /> <input type="text" name="text" id="user_login" class="input" value="" size="20" tabindex="10" /></label> </p> <p> <label>Password:<br /> <input type="password" name="password" id="user_pass" class="input" value="" size="20" tabindex="20" /></label> </p> <p class="submit"> <input type="submit" name="submit" id="submit" value="Log In" tabindex="100" /> </p> </form> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/155962-noob-php-problem/ Share on other sites More sharing options...
wildteen88 Posted April 28, 2009 Share Posted April 28, 2009 If you want the admin page to be "included" when the user successfully logs in then replace this else { ?> <div id="login_sucess"> <strong>LOGIN SUCCESSFUL</strong>: <a href="login.html">Click here</a> to continue.</div> <?php } ?> with else { include 'admin.php'; } ?> However whats stopping the user from bypassing your login form and going straight to admin.php? Link to comment https://forums.phpfreaks.com/topic/155962-noob-php-problem/#findComment-821140 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.