Hi, I've just started using php for one week and I really need help on the following code! Basically, I am trying to do a simple login submit and if username/password verified, it will move to next html/php page. I have a few questions:
1) How does php know that $username is from the form input name=username?
2) The example I was using was from http://www.zend.com/codex.php?id=242&single=1
I changed to the code below. When I asked it to write to write.txt for both $username and $password, the content was username is password is. Did I miss something?
2) Eventually, I would like to change the fopen to be "fopen( "nextpage.html", "r" )". But, the replacement doesn't work. What did I do wrong? I read about fpassthru do I need that to make the page automatically go next?
Please help!!!
Thanks!!
Here's the code:
<?php
function loginForm() {
global $PHP_SELF;
$header = '<HTML><HEAD><TITLE>PHP Login</TITLE></HEAD><body>;
$footer = '</BODY></HTML>';
echo $header;
?>
<FORM method="post" name="loginform" action="<?php doLogin(); ?>">
<TABLE ALIGN="CENTER">
<TR>
<TD>
<B><FONT COLOR="#336633" SIZE="+2">Username:</FONT></B>
</TD>
<TD>
<INPUT type="text" name="username" id="username" size="20" maxlength="16">
</TD>
</TR>
<TR>
<TD></TD>
</TR>
<TR>
<TD>
<P ALIGN="CENTER">
<B><FONT COLOR="#336633" SIZE="+2">Password: </FONT></B>
</TD>
<TD>
<P ALIGN="CENTER">
<INPUT type="password" name="password" id="password" size="20" maxlength="16"></P>
</TD>
</TR>
<TR>
<TD></TD>
</TR>
<TR>
<TD>
<P ALIGN="LEFT"></P>
</TD>
<TD>
<P ALIGN="LEFT">
<INPUT type=submit name="sent" id="sent" value="login">
<INPUT type="reset" name="reset" value="clear">
</P>
</TD>
</TR>
</TABLE>
</FORM>
<?php
echo $footer;
}
function doLogin() {
global $PHP_SELF, $sent, $username, $password;
$fp = fopen( "write.txt", "r+" );
fwrite( $fp, "username is $username\n" ); <--- in write.txt, both username and password
fwrite( $fp, "password is $password\n" ); <--- are blank.
fclose( $fp );
if( !$login_ok ) {
return 0;
}
}
// main
// Initializing Variables
$url = basename( $PHP_SELF );
if( !doLogin() ) {
loginForm();
}
if( (isset( $sent ) ) ) {
echo "Login successful ";
echo "for login name: <b>" .$username."</b><br>";
echo "<br><br><br><a href='nextpage.html'>Proceed</a>";
}
?>