0

How to make a login?

I'm not able to create a simple login in php in which after submitting the username and email... We get a call out ie.. When we submit the form the script echoes welcome "username", your e-mail address is "email". Can the community help me???

23rd Jan 2020, 12:55 PM
KASH
KASH - avatar
3 Answers
+ 1
KASH you can use session variables to assign session to the users have you tried anything if yes send the link of your code I'll fixed it for you
23rd Jan 2020, 1:01 PM
DishaAhuja
DishaAhuja - avatar
0
<?php session_start(); $errorMsg = ""; $validUser = $_SESSION["login"] === true; if(isset($_POST["sub"])) { $validUser = $_POST["username"] == "admin" && $_POST["password"] == "password"; if(!$validUser) $errorMsg = "Invalid username or password."; else $_SESSION["login"] = true; } if($validUser) { header("Location: /login-success.php"); die(); } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>Login</title> </head> <body> <form name="input" action="" method="post"> <label for="username">Username:</label><input type="text" value="<?= $_POST["username"] ?>" id="username" name="username" /> <label for="password">Password:</label><input type="password" value="" id="password" name="password" /> <div class="error"><?= $errorMsg ?></div> <input type="submit" value="Home" name="sub" /> </form> </body> </html> Here! :-)
23rd Jan 2020, 1:00 PM
Sebastian
0
Sebastian can you add the fopen, fwrite and fclose function in it for the data entered in the input
27th Jan 2020, 10:20 AM
KASH
KASH - avatar