I want to make a program that takes the input ie Username and Password from user , there is a submit button and if everything is correct then user should be able to access another webpage .
A rough blueprint is-
<form>
Username:<input type="text" name="name"size="15"><br>
Password:<input type="password" name="pass"><br>
<input type="submit" value="submit">
</form>
Now i don't know how to verify the password and username. My friend said it can be done using php. I want to know how it can be done. i know php so i can understand it. Please give the code. I know how to do the same in C++ but i am new to php so plz help.

Member Avatar for Zagga

Hi Jack_1,

for the very basics, you could start with

<?php
if (isset($_POST['submit'])){
	if ($_POST['name'] == "myname" && $_POST['password'] == "mypassword"){
		header("location:member.php");
	}
}
echo "<form method='post' action='" . $_SERVER['PHP_SELF'] . "'>";
echo "Name:<input name='name' type='text' />";
echo "Password:<input name='password' type='password' />";
echo "<input type='submit' name='submit' value='Login' />";
echo "</form>"
?>

This has absolutely NO SECURITY measures in place at all, but gives you an idea.

To make it more secure, you would need to compare the given name and password to ones stored in a database (not include it in the code), and quite a bit more.
The username for the above code is "myname", the password is "mypassword" and the correct details would forward the user to member.php.


Hope this helps.
Zagga

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.