I'm setting up a plain HTML/PHP(to perform include()
) website for demo purposes strictly. I'd like to make a functional login page that redirects the user based on the credentials used.
For example: If the user/pass combination used was "editor" and "123456" respectively, then he will be redirected to /editor.html
. The same for "admin" and "user" members...
Certainly I already have the basic login layout in HTML, but how can I make it functional that way? How could I achieve this effectively?
Thank you very much for your time, Regards
Html code
<div id="pane-login" class="panel-body active">
<div class="form-group">
<div class="inputer">
<div class="input-wrapper">
<input type="text" class="form-control" placeholder="User">
</div>
</div>
</div>
<!--.form-group-->
<div class="form-group">
<div class="inputer">
<div class="input-wrapper">
<input type="password" class="form-control" placeholder="Pass">
</div>
</div>
</div>
<!--.form-group-->
<div class="form-buttons clearfix">
<label class="pull-left">
<input type="checkbox" name="remember" value="1">
Remember</label>
<button type="submit" onclick="location.href='index.php';" class="btn btn-success pull-right">Enter</button>
</div>
<!--.form-buttons-->
</div>
Okay so first of all, your form isn't actually a form here.
Prepend to the inputs:
<form name="formname" method="POST" action="yourphpfile.php">
and end with a
</form>
Add a "name" value to each of the inputs Remove the onClick from your submit Button.
In your php file, do the following:
$username = $_POST["firstinputname"]
$password = $_POST["password"]
Evaluate the login info and do a switch case in case login is correct;
switch($username)
{
case "editor":
header('Location: /yourlocation.php');
break;
case "another":
header('Location: /anotherlocation.php');
break;
}
You make the form using HTML, then in PHP you use the $_POST like this for example :
<?php
if(isset($_POST['username']) && isset($_POST['password']))
{
if($_POST['username'] == "editor" && $_POST['password'] == "123456")
{
header('Location: /editor.html');
}
}
?>
to make it dynamic you can use mysql ( type "login php + mysql" in google )