Cramster.com - Homework Solutions, Lecture Notes, Exams, and Free Online Homework Help
Sign Up Now! Login Customer Support
McAfee Secure sites help keep you safe from identity theft, credit card fraud, spyware, spam, viruses and online scams
Problem Solved.
    Home    
    Homework Help    
   Answer Board   
    Resources (Beta)    
   
Member's Topic Headline:

Modern Programming Languages

Know the answer? Have a better solution? Share it.
Get Help Now.
View homework problems
explained for free!
Member Testimonials

Question:

Advertisement:

Answer | Ask New Question | Customize Profile | Leaderboards | 
FAQ

Member's Avatar

Rookie
Karma Points: 0
Respect (0%):
Date Posted: 7/25/2008 12:48:52 AM  Status: Live
Modern Programming Languages
Course Textbook Chapter Problem
N/A Modern Programming Languages N/A N/A
Question Details:
  1. For login to VULMS you need your username (ID) and password. Write a simple program in PHP for user authentication on a web site. If you are not registered please mention the alternative path for registration (through coding). Please show the role of MYSQL data base in this example/program.

Answers:

Member's Avatar

Mentor
Karma Points: 564
Date Posted: 8/1/2008 3:00:33 AM  Status: Live
Asker's Rating: None Provided    Moderator's Rating: N/A
Response:
 
Dear..
 
  Login page:
    <? 
        // start session
            session_start(); 
       // convert username and password from _POST or _SESSION
            if($_POST)
              {
                  $_SESSION['username']=$_POST["username"];
                  $_SESSION['password']=$_POST["password"];  
               }
      
     // Sql query for a username&password 
         $result=mysql_query("select * from users where username='" . $_SESSION['username'] . "' and password='" . $_SESSION['password'] . "'"); 
     
     //     retrieve number of rows resulted
        $num=mysql_num_rows($result);  
     //    print login form and exit if failed.
         if($num < 1)
           {
               echo "You are not authenticated.  Please login.<br><br> 
                 <form method=POST action=index.php>
                          username: <input type=text name=\"username\"> 
                          password: <input type=password name=\"password\">
                     <input type=submit> 
                </form>"; 
             exit;
          }
    ?>

  Slq-Query

    CREATE TABLE USERS(  User_id int(8)unsigned NOT NULL auto_increment, username varchar(20) NOT NULL default '', password varchar(20) NOT NULL default '',
       PRIMARY KEY (user_id)  )TYPE=MyISAM

         note:  if you want to use any text editor, then  edit the connect.php with your mysql settings.

  connect.php

   <?
    // Login & Session example by sde connect.php
    // replace with your db info
          $hostname="localhost";
          $mysql_login="myusername";
          $mysql_password="mypass";
          $database="test";

        if (!($db = mysql_connect($hostname, $mysql_login , $mysql_password)))
          {
               die("Can't connect to mysql.");    
             }
          else
             {
                if (!(mysql_select_db("$database",$db))) 
                   {
                      die("Can't connect to db.");
                     }
              }
       ?>

 I hope it is use full to you. If any doubts , just remember CRAMSTER is with you.




By reading or posting messages on these forums, you are agreeing to the Answer Board's Terms of Service and Conduct (TSC).


About Cramster | Terms of Use | Privacy Policy | Contact Us | Press Room | Site Map | Support | Anti-Cheating Policy

Cramster.com is not affiliated with any publisher. Book covers, title and author names appear for reference only.
Copyright © 2008 Cramster, Inc.