Jump to content

php for this?


Reaper0167

Recommended Posts

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

Link to comment
Share on other sites

 
<?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.

Link to comment
Share on other sites

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>"
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.