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
https://forums.phpfreaks.com/topic/143283-php-for-this/#findComment-751475
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
https://forums.phpfreaks.com/topic/143283-php-for-this/#findComment-751482
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
https://forums.phpfreaks.com/topic/143283-php-for-this/#findComment-751496
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.