Jump to content

Login Problem


googlemaniac

Recommended Posts

I want to password protect a page.I created a table in mysql database for password and put in a default value [the password of the page].what would the form code be which connects with the database?eg,If i want to protect 1.php with the password 'mypassword' ,what would the code be for 1.php to connect with the database?note: jst the password and no username... thanks in advance.. :)

Link to comment
Share on other sites

If it's just a single password you're storing, I don't see why you even need a database.You don't seem to understand forms and databases very well. There is not form code that sends data to the database. A form sends user input to the server. A server-side language does whatever it wants with the data.Learn how to receive form data:http://w3schools.com/php/php_forms.asphttp://w3schools.com/php/php_post.aspAnd how to work with databases:http://w3schools.com/php/php_mysql_intro.aspIf you want to make any web applications you need to actually understand what you're doing, not just take some code and modify it to make it work the way you want it.

Link to comment
Share on other sites

If it's just a single password you're storing, I don't see why you even need a database.You don't seem to understand forms and databases very well. There is not form code that sends data to the database. A form sends user input to the server. A server-side language does whatever it wants with the data.Learn how to receive form data:http://w3schools.com/php/php_forms.asphttp://w3schools.com/php/php_post.aspAnd how to work with databases:http://w3schools.com/php/php_mysql_intro.aspIf you want to make any web applications you need to actually understand what you're doing, not just take some code and modify it to make it work the way you want it.
so..i have to build the page,use the post function,compare the user input with the data in the second page,and if they both are the same,redirect the user to the next page..rite?so the page code will be..
<form action="2.php" method="post">  <input type="password" name="textfield"></form><input type="submit" /></form>

and 2.php will contain the password..plus redirection to 3.phpand the code for that would be...??

Link to comment
Share on other sites

You may want to reconsider the way these pages fit together. The simplest plan is to keep all your content pages/scripts separate from your login page/script. So the top of each page would look a bit like this:login.php

<?php$bad = false;if (isset($_POST['pw']) ) {	if ($_POST['pw'] == 'my_password') {		session_start();		$_SESSION['logged'] = 'ok';		header("Location: page1.php");	}else {	// bad password	$bad = true;	}} else {	// no password}?><form>blahblah<?php if ($bad) {echo 'Password incorrect';} ?>blah

Note that it is common for login.php to contain the login form AND the login script. The form document just submits to itself. If no password has been sent, the login form is printed normally. If the password fails, the login form is printed, but some sort of message or image gets added to tell the user about the error.page1.php

<?phpsession_start();if (!isset($_SESSION['logged']) ) {	header("Location: login.php");}?><!-- html for logged-in users -->

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...