Authendication problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
umapathy
Forum Newbie
Posts: 14
Joined: Fri Jul 28, 2006 2:21 am
Location: chennai - india

Authendication problem

Post 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
klarinetking
Forum Commoner
Posts: 59
Joined: Mon Jul 24, 2006 9:43 am

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post 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.
Post Reply