By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

Log in page

P: n/a
Hi,

trying to create a simple login page using php and a post form.

The following requirement holds,
1. there should NOT be any DB.
2. One user and one password is enough (yeah, said it was a simple
one...)

Tried with a function check_user() in a lib php-file, and a post form
in the login page. Code as follow:

<?php

function check_user(){
global $userfield, $pwdfield;

if( strcmp($_POST[$userfield],"user") == 0 ) {

if( strcmp($_POST[$pwdfield],"pwd") == 0 ) {
// Correct user
echo("correctdir/album.htm");
}
else {
// Wrong pwd
echo("../somdir/default.htm");
}
else {
// wrong user
echo("../otherdir/default.htm");
}
}

}
?>

and the login page for is:
<?PHP
require('../somelib/login_lib.php');
?>

....
<form name="form1" method="post" action="<?php check_user();?>">
<input type="text" name="userfield" >
<input type="password" name="pwdfield" >
<input type="submit" name="Log in" value="Log in">
</form>

....

Can't get it to work. Any good idea to resolve this? Any other more
brilliant solution instead of this?

br,
Magnus
Jul 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
tlakso wrote:
The following requirement holds,
1. there should NOT be any DB.
2. One user and one password is enough (yeah, said it was a simple
one...) Can't get it to work. Any good idea to resolve this? Any other more
brilliant solution instead of this?


You could do this:

if (!isset($_SESSION["pasword"])){
// generate a password, store it to above place and mail it to yourself
} else {
// output form/validate form when submited
}

--
Dado

The original point and click interface was a Smith & Wesson

Jul 16 '05 #2

P: n/a
tl****@hotmail.com (tlakso) wrote in message news:<85**************************@posting.google. com>...
Hi,

trying to create a simple login page using php and a post form.
Certainly you have to learn PHP. Buy some good books or Google
for PHP articles.... I'll try to pointout your mistakes...

The following requirement holds,
1. there should NOT be any DB.
2. One user and one password is enough (yeah, said it was a simple
one...)

Tried with a function check_user() in a lib php-file, and a post form
in the login page. Code as follow:

<?php

function check_user(){
global $userfield, $pwdfield;
for what???
if( strcmp($_POST[$userfield],"user") == 0 ) {
Try $_POST['userfield']


if( strcmp($_POST[$pwdfield],"pwd") == 0 ) {
// Correct user
echo("correctdir/album.htm");
}
else {
// Wrong pwd
echo("../somdir/default.htm");
}
else {
// wrong user
echo("../otherdir/default.htm");
}
}

}
?>

and the login page for is:
<?PHP
require('../somelib/login_lib.php');
?>

...
<form name="form1" method="post" action="<?php check_user();?>">
^^^^^^^^^^^^^^^^^^^^^
<input type="text" name="userfield" >
<input type="password" name="pwdfield" >
<input type="submit" name="Log in" value="Log in">
</form>

...

Can't get it to work. Any good idea to resolve this? Any other more
brilliant solution instead of this?

Basci debugging trick: Run your PHP code on a webserver and
"view source" of the html page to verify.

HTH,
R. Rajesh Jeba Anbiah

---
Email: rrjanbiah-at-Y!com
Jul 16 '05 #3

P: n/a
tl****@hotmail.com (tlakso) wrote in message news:<85**************************@posting.google. com>...

Tried this with $_POST['userfield'] in strcmp, but still get this:
"
You don't have permission to access /<br /><b>Notice</b>: Undefined
index: userfield in <b>f:\apache\lib\login_lib.php</b> on line
<b>11</b><br /> on this server.
"

so, the userfield index is undefined. PHP version is 4.3.2 and apache
1.3. Any clue?


It's because, you're trying to get the values before POST.
<form name="form1" method="post" action="<?php check_user();?>">


^^^^^^^^^^^^^^^^^^^^^


What do you mean? Is it not possible to call this function there?

You can call a function, but not like JS. Obviously you have to
learn PHP.... If you know HTML, "view html source" of your PHP code.

---
Email: rrjanbiah-at-Y!com
Jul 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.