Hi Ronald,
> Hello there fellow programmer,
>
> I just started learning PHP (I got version 4 installed with Apache on a
> Win98 machine). At the moment I'm trying to write a little program that
> verifies a user login.
> I know the program is not professional but for me it will do. Only I got
> stuck with the following problem. I have written a class (I'm not very
sure
> if this is the right way to do this) in which I specified a function that
> does the password check.
> Now I like the program to check the password and return me a true or a
false
> which I can read from somewhere else in my program.
> I wrote it like this:
First of all, you don't need a class for this. Unless you expect the program
to get a lot more complicated, you could just use a function.
>
> <html>
> <head>
> <title>Password Check</title>
>
> <?PHP class password
> {
> function checkpwd()
> { ?>
>
> <FORM ACTION="<?php print("$PHP_SELF"); ?>" METHOD="POST">
> User name is:<BR>
> <INPUT TYPE="text" NAME="UserName"> <P>
>
> <?php echo "Give Password:<BR>" ?>
>
> <INPUT TYPE="PASSWORD" NAME="passwd">
> <INPUT TYPE="HIDDEN" NAME="GeefInfo" VALUE=1> <p>
> <INPUT TYPE="submit">
>
> <?PHP if (IsSet($this->GeefInfo)&&IsSet($this->UserName))
> {
> $this->UserName=strtoupper($this->UserName);
> $this->passwd=strtoupper($this->passwd);
$this->GeefInfo and $this->UserName will never be set. You need to change
this to something like:
if (isset($HTTP_POST_VARS["GeefInfo"]) &&
isset($HTTP_POST_VARS["UserName"]))
>
> if (IsSet($this->passwd))
Similarly here.
if (isset($HTTP_POST_VARS["passwd"]))
> {
> if ($this->passwd=="MYPASS" && $this->UserName=="RONALD")
> {
> $this-> testvar=1;
> exit(1);
> }
> else
> {
> $this-> testvar=0;
> exit(0);
I think you might be expecting exit() to do something different to what it
does here. The function exit() will terminate script execution. I suspect
what you wanted was return.
return 1;
else
return 0;
> }
>
> }
>
> }
> }
> }?>
>
> </head>
> <body>
>
> <?php $exec_pwd=new password;
> $vexec_pwd->checkpwd();
> print $exec_pwd; // Where is my output ?????
You won't get any output. $exec_pwd contains an object (an instance of your
"password" class).
If you want to output the return value from checkpwd(), do:
$exec_pwd = new password;
print $exec_pwd->checkpwd();
I think you may be a bit confused about how variables, classes and objects
work in PHP. Have a closer read through the manual. Moreover, if you're just
starting out with PHP then steer clear of objects entirely - you don't need
them!
> ?>
>
> </body>
> </html>
>
> If you can and like to help me I will be very pleased.
> Thanks in advance !!!
>
> Ronald
Hope this helps.
Cheers
Simon Garner
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]