password 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
crayon
Forum Newbie
Posts: 5
Joined: Sat Jan 10, 2004 10:06 pm

password problem

Post by crayon »

hi all

just learning PHP week ago,anyone can enlighten me,what wrong the this coding which key in a correct password still showing wrong password.

many thkx

<html>
<head>
<title>PHP testing</title>
</head>
<body>
<?php
$loginpass = 'test';
if ($pw == $loginpass)
{
....do something
}
else
{
print("Error. That is not the correct password.\n");
}
?>
</body>
</html>
crayon
Forum Newbie
Posts: 5
Joined: Sat Jan 10, 2004 10:06 pm

Post by crayon »

I using RH9.0 localhost,file store in /var/www/html/
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Try echo "Error. That is not the correct password.\n";
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

That wouldn't matter.

uhh.. you didnt declare $pw anywhere?
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Most probably the $pw is coming from a form. I doubt anyone uses $_GET to authenticate 8O. Try changing the $pw to $_POST['pw']

-Nay
crayon
Forum Newbie
Posts: 5
Joined: Sat Jan 10, 2004 10:06 pm

Post by crayon »

Thkx for everyone helping me,this my fault didn't read thru the documentation,that
php.ini register_globals need set it to "On".
pls accept my apologize.
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

I know the echo things wouldn't matter..but..echo is so much better than print.
User avatar
thomasd1
Forum Commoner
Posts: 80
Joined: Sat Nov 22, 2003 2:48 pm
Location: Belgium

Post by thomasd1 »

Nay wrote:Most probably the $pw is coming from a form. I doubt anyone uses $_GET to authenticate 8O. Try changing the $pw to $_POST['pw']

-Nay
8O
explain ?
what's the difference?

ohno, i've been doin it all wrong :oops: :o
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

When you use a form there are 2 different ways to send the data, GET and POST.

Code: Select all

<form action="authenticate.php" method="POST">

OR

<form action="authenticate.php" method="GET">
GET will send the data straight through the URL and then on authenticate.php the URL will be like this:

authenticate.php?username=DuFF&password=fakepswd

If you use POST it will not pass the data through the URL and therefore is much harder to manipulate the form data.

On the page recieving the form, depending on which method you use, you need to use $_GET['username'] or $_POST['username']
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

crayon wrote:Thkx for everyone helping me,this my fault didn't read thru the documentation,that
php.ini register_globals need set it to "On".
pls accept my apologize.
Just to point something out. You should not change te php.ini setting of register_globals to 'On' to solve the problem, but rather learn how to use $_POST / $_GET (as mentioned by fellow posters).
register_globals are set to off for security reasons as default and should imho never be touched.
crayon
Forum Newbie
Posts: 5
Joined: Sat Jan 10, 2004 10:06 pm

Post by crayon »

JAM wrote:
crayon wrote:Thkx for everyone helping me,this my fault didn't read thru the documentation,that
php.ini register_globals need set it to "On".
pls accept my apologize.
Just to point something out. You should not change te php.ini setting of register_globals to 'On' to solve the problem, but rather learn how to use $_POST / $_GET (as mentioned by fellow posters).
register_globals are set to off for security reasons as default and should imho never be touched.
thkx for your advice,I just insert $_POST and set php.in off and it work.
many thkx for everyone.
User avatar
thomasd1
Forum Commoner
Posts: 80
Joined: Sat Nov 22, 2003 2:48 pm
Location: Belgium

Post by thomasd1 »

DuFF wrote:When you use a form there are 2 different ways to send the data, GET and POST.

Code: Select all

<form action="authenticate.php" method="POST">

OR

<form action="authenticate.php" method="GET">
GET will send the data straight through the URL and then on authenticate.php the URL will be like this:

authenticate.php?username=DuFF&password=fakepswd

If you use POST it will not pass the data through the URL and therefore is much harder to manipulate the form data.

On the page recieving the form, depending on which method you use, you need to use $_GET['username'] or $_POST['username']
so, GET reads data out of url's..
and POST ... not ....:?
Post Reply