Reputation: 1048
my website is http://setch.me
I have a page that I use to add new entries to the artists table, how do I set a simple username/password
to this page with normal php(no framework)?
I've looked it up and I found similar questions but none of them is using php only
Upvotes: 0
Views: 289
Reputation: 252
Php-login comes with three versions. The first one (One-file version) maybe is what you are looking for.
Upvotes: 0
Reputation: 388
It's simply you just need to create a form
<form action="" method="post">
<input type="text" name="user"/>
<input type="password" name="pass"/>
</form>
And submit data and compare it with your private username and password example
<?php
if(isset($_POST["submit"])) {
// Here you put you own login data you can use mysql to get it
$username = "admin";
$password = "admin";
$username_post = htmlspecialchars($_POST["user"]);
$password_post = htmlspecialchars($_POST["pass"]);
if(($username_post == $username) && ($password_post == $password)) {
session_start();
$_SESSION["admin"] = $username;
}
}
?>
and put this code in page that you want to add new entries
<?php
session_start();
if(empty($_SESSION["admin"])) {die();}
?>
Upvotes: 1