Simple user login question

I have an idea for a simple user login where the user would be redirected to his/her personal page by filling a username/password form which would take them to web folder(username) and page(password.html) within my website.

The personal page would not actually contain any personal info, just a message form for them to send a personal message/request, so the security is not critical. I would manually create a folder and page for each user as I accept them. I only accept clients in person after a consultation. The site message form would just be an alternative to using the phone.

There should be no error message or redirect on a username/password entry that does not equate to a folder/page. No help, No signup, No recover password, Nothing. They either enter it correctly or it just looks at them.

Is this doable in php/html only or would it require such as js, and do you see any issues. Any help is appreciated. I haven’t used php for nearly 20 years, so I’m pretty lost.

This isn’t needed. You would create generic templates that just change with the user details. Think Amazon products, a new file isn’t created for every product, the data is just injected into the page.

Think Amazon products…

LOL. Think I haven’t touched web design for 20 years…

Anyway…

<form onsubmit="location.href='http://www.website-name.com/' + document.getElementById('user').value  +  '/' + document.getElementById('pass').value + '.html'; return false;">
<input type="text" id="user" /> <input type="text" id="pass" /> <input type="submit" value="Submit" />
</form>

This works for the main issue. I would still like to know a way to prevent the “page not found” if someone enters other than actual directory/page info, if that’s possible?

If you could expound on “You would create generic templates that just change with the user details” it would be appreciated.

Thanks for the response.

  • JavaScript is not necessarily required.
  • Creating a login script can be quite a challenge for a beginner
  • creating a new page for every user sounds like a bad idea

Why don’t you start with a one field form where anybody can enter his name and after a submit you show your contactform so that anyone can enter his message?

Building a login system is a bit overkill if there aren’t security issues and which also needs maintenance e.g. registering new users and remove old ones. And of course it is so human to forget your password…

Thanks frankbeen,

but the concept here is that I only create pages for clients I acquire in person, so there will be no registering, and I will probably never have more than a dozen clients.

I’m sure there is a better way to do this and I’m open to any suggestions and help.

So let me ask why you want to write a dozen of the same forms? The better approach like mentioned earlier is always to write dynamic pages with a mix of static content and content that comes from a database, the dynamic content.

Not sure why you both only reply to that part. I could use some help/advise with the coding of the login form.

Building a login system (not only the form) could not be explained in a few sentences. But luckily there are a lot of tutorials available. I quick search on “Uncle Googl” brought me this: https://codeshack.io/secure-login-system-php-mysql/

Thank you very much.

1 Like

The first part is very basic. This was written in 2 minutes.

<?php
session_start();

$pdo = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
	$sql = "SELECT user_id, password FROM User WHERE username = ?";
	
	$stmt = $pdo->prepare($sql);
	$stmt->execute([$_POST['username']]);
	$result = $stmt->fetch();
	if(password_verify($_POST['password'], $result['password']))
	{
		$_SESSION['user'] = $result['user_id'];
		header("location: template.php");
		exit;
	} else {
		$msg = "Username or Password is not valid";
	}
	
}

?>

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">

  <title>Site - Login</title>
  
  <link rel="stylesheet" href="css/styles.css?v=1.0">

</head>

<body>
<?php if(isset($msg)) echo "<p>$msg</p>"; ?>
<form method="post">
	<p>Username: <input type="text" name="username"></p>
	<p>Password: <input type="password" name="password"></p>
	<input type="submit" value="Login">
</form>

</body>
</html>

And I’m guessing you’re quite impressed with yourself.

Yet, not at all what I asked for help with.
If you don’t know and you must answer anyway, then say… “I don’t know.”
It would be better not to answer at all, but then you could not display your superiority.

I have looked through many of the posts here and I find that you answer many of them, yet you don’t really answer them at all. Funny, yes?

Thanks for the effort.

That’s exactly what you asked for, but thanks for playing.

Since you feel that is not what you asked for, what is it that you are asking for?

As for being pleased with myself, that’s very basic coding. Where I am pleased with myself, is overseeing 40 devs on 3 continents; Designing systems than have roughly 20 million users a week; And have annual budgets that cost more than your entire housing area. That’s where I’m pleased with myself. And my superiority comes from this not being a hobby, but something that very large companies pay a lot of money for me to do correctly the first time, for more than thirteen people to use. So yes, your project pails in comparison to what I typically work on, and yet I still attempted to help you do it correctly, stupid me.

Hope a few of your clients tell you that you don’t know what you’re doing either. And maybe you give back to your industry as much as I donate time and effort to the betterment of mine.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service