Easy login script without database
It's not an ideal solution but here's a quick and dirty example that shows how you could store login info in the PHP code:
<?php
session_start();
$userinfo = array(
'user1'=>'password1',
'user2'=>'password2'
);
if(isset($_GET['logout'])) {
$_SESSION['username'] = '';
header('Location: ' . $_SERVER['PHP_SELF']);
}
if(isset($_POST['username'])) {
if($userinfo[$_POST['username']] == $_POST['password']) {
$_SESSION['username'] = $_POST['username'];
}else {
//Invalid Login
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login</title>
</head>
<body>
<?php if($_SESSION['username']): ?>
<p>You are logged in as <?=$_SESSION['username']?></p>
<p><a href="?logout=1">Logout</a></p>
<?php endif; ?>
<form name="login" action="" method="post">
Username: <input type="text" name="username" value="" /><br />
Password: <input type="password" name="password" value="" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
PHP login page without database
you can do this
after you post your form values to the server page
just use if conditions and pattern match(for email)
$password= test_input($_POST["password"]);
if(empty($password)){
$err[]='password Required';
}
if (!preg_match("/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{8,12}$/",$password)) {
$err[]= "Only letters and white space allowed";
}
if (empty($_POST["email"])) {
$err[]= "Email is required";
} else {
$email= test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$err[]= "Invalid email format";
}
}
if(!empty($err)){
//// echo "email or password error//
var_dump($err);
}else{
///do your success
}
tinker a bit
how to create a login on php without database ?
you can use a simple xml file to save the pass and login,
or use a NOSQL that you don't need to install it
Best login management solution without database in PHP
There are other solutions like that, but I can't find nicer links right now:
- http://webscripts.softpedia.com/script/Authentication/AuthMan-Free-42216.html
- http://www.phpkode.com./scripts/item/passwdauth/
- http://www.hotscripts.com/listing/htaccess-manager-lite/
- http://www.hotscripts.com/listing/needlock-access-management-system/
- http://www.hotscripts.com/listing/dirlock/ (Ooops. Too many hotscripts links. So just saying: not affiliated with that. :] And certainly not endorsing it!)
Anyway. These scripts store usernames and passwords into a .htpasswd
file. This can be used independently from the PHP script. .htaccess
and .htpasswd
is common authentication scheme for Apache webservers. See this tutorial: http://www.javascriptkit.com/howto/htaccess3.shtml or the Apache manual: http://httpd.apache.org/docs/2.0/howto/auth.html
You could use the class itself for authentication, but it doesn't look very current. The login management tool might be useful to you. (But again: there are probably easier ones to find.)
Login form php without database - reloading
Something like this should do the job: (untested)
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if ($username =='john' AND $password=='abc') {
header("Location:/detalhes.php");
} elseif ($username!='john' OR $password!='abc'){
$_SESSION['msg'] = "Wrong, try again.";
header("Location:http://localhost/index.php");
}
?>
log.php
<?
session_start();
<?php if(isset($_SESSION['msg']))
echo $_SESSION['msg'];
unset($_SESSION['msg']);
?>
Login Form use ReactJS (without database) with map()?
You can use .some()
method.
doc: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some
Something like this
var username = e.target.elements.username.value;
var password = e.target.elements.password.value;
if(users.some((elem) => elem.username === username && elem.password === password)) {
// when authentication is valid
} else {
// not a valid username / password
}
Related Topics
How to Rename Column in Laravel Using Migration
Phpexcel_Writer_Exception with Message "Could Not Close Zip File PHP://Output."
Conditional Switch Statements in PHP
What Is the Best Method to Prevent a Brute Force Attack
Type Hinting in PHP 7 - Array of Objects
Location for Session Files in Apache/Php
What Do Two Colons Mean in PHP
How to Receive a File via Http Put with PHP
Vcruntime140.Dll 14.0 Not Compatible with PHP Build
Parameter Type Covariance in Specializations
Phpmailer Sending Mail to Spam in Hotmail. How to Fix
In PHP, How to Add an Object Element to an Array
Aws Sdk for PHP: Error Retrieving Credentials from the Instance Profile Metadata Server
How to Check If an Entered Value Is Currency
PHP Random Url Names (Short Url)