Reaper0167 Posted January 31, 2009 Share Posted January 31, 2009 i want to display the username password text fields if a user is not logged in. and once the user is logged in, something like welcome $username would be there instead of the login text fields. Quote Link to comment Share on other sites More sharing options...
void Posted January 31, 2009 Share Posted January 31, 2009 good. you can start by reading about sessions :-) Quote Link to comment Share on other sites More sharing options...
chronister Posted January 31, 2009 Share Posted January 31, 2009 <?php if(isset($_SESSION['loggedIn'])) { // show relevant information }else{ // show login form } ?> Quote Link to comment Share on other sites More sharing options...
Reaper0167 Posted January 31, 2009 Author Share Posted January 31, 2009 i know about sessions and <?php if(isset($_SESSION['loggedIn'])) { // show relevant information }else{ // show login form } ?> i see some code with EOD, is that something i should look into also Quote Link to comment Share on other sites More sharing options...
justinh Posted January 31, 2009 Share Posted January 31, 2009 <?php session_start(); if(isset($_GET['submit'])){ $username = $_GET['username']; $password = $_GET['password']; if($username == "usernamegoeshere" && $password == "passwordgoeshere"){ $_SESSION['loggedin'] = 1; $_SESSION['username'] = "Justin"; }else{ ?> <html> <head> </head> <body> <fieldset> <font color="red"> Invalid Login.</font> <legend> Login </legend> <form input="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="username"> Account Name </label> <input type="text" name="username" /> <br /> <label for ="passsword"> Password </label> <input type="password" name="password" /> <br /> <input type="submit" value="Login!" name="submit"> </form> </fieldset> </body> </html> <?php } } if($_SESSION['loggedin'] == 1){ echo "Welcome " . $_SESSION['username'] ."!"; }else{ ?> <html> <head> </head> <body> <fieldset> <legend> Login </legend> <form input="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="username"> Account Name </label> <input type="text" name="username" /> <br /> <label for ="passsword"> Password </label> <input type="password" name="password" /> <br /> <input type="submit" value="Login!" name="submit"> </form> </fieldset> </body> </html> <?php } ?> this hasn't been tested, but should do what you want it do. The next step would be implementing database queries to check and see if the username and password exist in a database. In this code above the username and password are stored in the code itself. Quote Link to comment Share on other sites More sharing options...
Reaper0167 Posted January 31, 2009 Author Share Posted January 31, 2009 checking for the username and password would be inside of my login.php i'm just looking for the login form if no one is logged in and a welcome statement if someone is logged in. this is what i have so far. i don't think that i am echoing out the form correctly though. <?php session_start(); if(isset($_SESSION['auth'])) { echo "Welcome $username Log Out"; //Need to make Log Out a link } else { echo "<form name="form1" method="post" action="login.php"> <input type="text" name="username" id="username"> <input type="text" name="password" id="password"> <input type="submit" name="submit" id="submit" value="Login"> </form>" } ?> Quote Link to comment Share on other sites More sharing options...
chronister Posted January 31, 2009 Share Posted January 31, 2009 echo '<form name="form1" method="post" action="login.php"> <input type="text" name="username" id="username"> <input type="text" name="password" id="password"> <input type="submit" name="submit" id="submit" value="Login"> </form>'; Quote Link to comment Share on other sites More sharing options...
JewGold Posted January 31, 2009 Share Posted January 31, 2009 You could also use cookies. Make sure to md5 them though. Quote Link to comment 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.