Jump to content

Making a login script with a session


bytes

Recommended Posts

I completed my login script consist of two php.

 

Index.php

 

<html>
<body>
<form id="form1" name="form1" method="post" action="login.php">
  <div align="center">
    <p>Username : 
      <input type="text" name="username" />
  </p>
    <p>Password : 
      <input type="text" name="password" />
    </p>
    <p>
       <input name="Submit" type="submit" id="Submit" value="Login" />
</p>
  </div>
</form>
</body>
</html>

 

Login.php

<?php

$user = "admin";
$pass = "admin";

if ($_POST['username'] == $user and $_POST['password'] == $pass) {
echo 'Successfully login.';
} else {
  echo 'Invalid username/password.';
}

?>

 

I want to make a login script that use session and after I login it will shows me the control panel. Thanks  :D

 

 

Link to comment
https://forums.phpfreaks.com/topic/194637-making-a-login-script-with-a-session/
Share on other sites

I completed my login script consist of two php.

 

Index.php

 

<html>
<body>
<form id="form1" name="form1" method="post" action="login.php">
  <div align="center">
    <p>Username : 
      <input type="text" name="username" />
  </p>
    <p>Password : 
      <input type="text" name="password" />
    </p>
    <p>
       <input name="Submit" type="submit" id="Submit" value="Login" />
</p>
  </div>
</form>
</body>
</html>

 

Login.php

<?php

$user = "admin";
$pass = "admin";

if ($_POST['username'] == $user and $_POST['password'] == $pass) {
echo 'Successfully login.';
} else {
  echo 'Invalid username/password.';
}

?>

 

I want to make a login script that use session and after I login it will shows me the control panel. Thanks  :D

 

There are many of these pre-made scripts out there. I would advise using one of those instead of re-inventing the wheel unless your circumstances necessitate doing something different.

Basically you will need a database to hold a username and password. You will want a way to encode the password. You can look into the md5 function for this. You will also need to learn how to use sessions. Or you can do a simple google search for php login script and find one you like :)

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.