Basic Question

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
User avatar
Strider64
php-forum Active User
php-forum Active User
Posts: 286
Joined: Sat Mar 23, 2013 8:24 am

Re: Basic Question

Post by Strider64 » Thu Apr 11, 2013 7:54 am

I use a hidden type for older version of Internet Explorer sometimes flakes out at the submit button. You have to have the method="post" in you form statement.

Code: Select all

<form class="login-form" action="login.php" method="post"> 
                                      
                     <input type="hidden" name="action" value="login" >
                    
                     <label class="input-style" for="username">User Name</label>
                     <input type="text" onfocus="if (this.value == 'User Name') this.value = '';" value="User Name" name="username" id="username" >
                     <br>
                     <label class="input-style" for="password">Password</label>
                     <input type="password" name="password" id="password" value="" >
                     <br>                  
                    
                     <input type="submit" id="login" value="Login" >
                     <a class="link-style" href="captcha.php" target="_self">Register?</a>
               </form>
Then in you the login.php (or whatever filename it is) you might do something like the following:

Code: Select all

<? 

define('DB_HOST', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '****');
define('DB_NAME', 'your_database');

header('Content-Type: text/html; charset=utf-8');
session_start();
/* I usually put the above in a separate file called common.php */
/* then i simple just put it at the top of my php file                 */
/* <?php require("includes/common.php"); ?>                         */

if (isset($_POST('action')) {
   if ($_POST('action') == 'login') {
        $username = htmlspecialchars($_POST('username')); // Make sure you encapsulate any variable that a user can change. 
        $password = htmlspecialchars($_POST('password')); // Make sure you encapsulate any variable that a user can change. 
        //......more php code to check user's credentials 
  }
} 

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest