Kareem Kamal
Kareem Kamal

Reputation: 1048

how to restrict access to certain pages on my website

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

Answers (2)

cameraman
cameraman

Reputation: 252

Php-login comes with three versions. The first one (One-file version) maybe is what you are looking for.

Upvotes: 0

Mourad Karoudi
Mourad Karoudi

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

Related Questions