Here is simple script for PHP, Apache 2 and MySQL for user login and password with authentication at server.
Make a simple form with two input boxes for login and password.
Make a simple form with two input boxes for login and password.
Login.php
<html>
<body>
<form action="loginresult.php" method="post">
Login: <input type="text" name="login" /> <br/>
Password: <input type="password" name="password" /> <br/>
<input type="submit" />
</form>
</body>
</html>
When user submits form then request is sent back to sever and server passes the login and password information (contained in two variables "login" and "password" respectively) to "loginresult.php" file available at server. Then using PHP and MySQL we authenticate this information to check whether username and password exist in our database or not. Here is script for loginresult.php file.
LoginResult.php
<html><body>
<?php
$login = $_POST["login"];
$password = $_POST["password"];
$con = mysql_connect("localhost", "root", "123");
if (!$con)
{
echo "can not connect to databaser server";
}
mysql_selectdb("mydb", $con);
$sql = "SELECT name FROM users WHERE name='$login' AND password='$password'";
$result = mysql_query($sql,$con);
if ($row = mysql_fetch_array($result))
{
echo "Login successful. Welcome back ".$row['name'];
}
else
{
echo "login failed, get lost";
}
mysql_close($con);
?>
</body>/html>
In above file we first get the login and password information passed from login.php page and store it in two variables. Then we start a connection with database server and store it in $con. Then we connect with the specific database and write run our query by passing login and password information. You can put your code in respective if-else blocks based on login result i.e., if login is successful or not.
I hope this was of some help. Thanks for visiting my site. Have fun coding. feedback is welcome.