Page 1 of 1

Authendication problem

Posted: Sat Aug 26, 2006 2:38 am
by umapathy
Dear Friends!

i have one page. in this page have 2 text box .(admin.php)
one is for username another one is for password.
if i give username=umapathy,password=india, the control goes to x.php.
what my problem is if i copied the url form the IE ex.http://154.56.45.334/umapathy/x.php and i past it to new ie this page is opening.
i want to restrict this action.
with out user and pass. this page should not be work.
how i want to write coding for this.
if any one knows please answer this

Thanks and Regards
umapthy

Posted: Sun Aug 27, 2006 11:26 pm
by klarinetking
Hi,

Basically, what you want to do is check that form values have been submitted.

Code: Select all

if ( isset($_GET['username']) )
{
     // Form processing here
}
else
{
     echo 'You need to enter your information';
}
$_GET['...'] should be the name of the field of your form, and you use $_GET when the form method is GET, or $_POST when the method is POST.

Hope this helps,

klarinetking

Posted: Sun Aug 27, 2006 11:50 pm
by RobertGonzalez
Anytime you have a page dedicated to processing form data, you should always check that the form was actually posted, and if not, redirect them to the form.

Use that logic with klarinetking's example code and see what you can come up with.

Posted: Mon Aug 28, 2006 1:52 am
by mickd
Or, if you'd prefer you can seperate the conditional statement from the actual processing logic by using the php function die() or exit().

For example,

Code: Select all

if (!isset($_POST['form']) ) {

// header("location: form.php");
die();

}

// Form processing logic here
It works the same, but in the end comes to your own personal preference.