FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Is this code good?

 


mtorregiani
Hi
I just found this code and I want to know if it is good, or if it has some troubles...

Code:

<?php

// Designate your username and password
$username = "user";
$password = "pass";

if ($_POST['user'] != $username || $_POST['pass'] != $password) {

?>

<h1>Login</h1>

<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
     <p><label for="user">Username:</label>

     <input type="text" title="Please enter your Username" name="user"></p>

     <p><label for="pass">Password:</label>

     <input type="password" title="Please enter your Password" name="pass"></p>

     <p><input type="submit" name="Submit" value="Login"></p>

</form>

<?php

}
else {

?>

<!-- Place the Password Protected content here -->

<p>Content.</p>

<?php

}

?>


Thanks
bladesage
It looks just fine from what I can tell.

I see no obvious flaws in it. It should work alright.
hexkid
mtorregiani wrote:
Hi
I just found this code and I want to know if it is good, or if it has some troubles...

Code:
...
<label for="user">Username:</label>
<input type="text" title="Please enter your Username" name="user">
...


The PHP part of it seems ok.
I have an HTML quirk for it though Smile

The label element specifies what other element it is a label for with the attribute for. But the value of the for attribute must be the same as the value of the id attribute of the associated control element, and you have no ids for your inputs!

You can simply code the labels without a for attribute and enclose the input within the label
Code:

<label>Username: <input type="text" title="Please enter your Username" name="user"></label>
mtorregiani
Thanks a lot.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.