Introduction to Web

imagessudo apt-get install apache2

//sudo ifconfig eth0 | grep inet | awk '{ print $2 }'

sudo apt-get install mysql-server

sudo apt-get install php5

installing  mysql dependencies
===============================
sudo apt-get install php5-mysql phpmyadmin

sudo apt-get install libapache2-mod-php5 php5-mcrypt

sudo nano /etc/apache2/mods-enabled/dir.conf

apt-cache search php5-

sudo nano /var/www/html/info.php

<?php
phpinfo();
?>

===============
 
proceed with working on login and registration system

=================================================

Version 1 (for login only)

==============
a)create a login form in index.php

<!DOCTYPE HTML>
<head>
</head>
<body>
  <form method="post" action="handle.php">
    <input type="text" name="username"/>
    <input type="password" name="password"/>
    <input type="submit" value="login"/>
  </form>

</body>


b)on click redirect to handle.php
  • b1)handle.php
		<?php
			echo $_POST['username'];
			echo $_POST['password'];
		?>
  • b2)create database handle
<?php
echo $_POST['username'];
echo $_POST['password'];


	 $DB_host = "localhost";
	 $DB_user = "root";
	 $DB_pass = "123";
	 $DB_name = "testdb";
	 
	 $MySQLi_CON = new MySQLi($DB_host,$DB_user,$DB_pass,$DB_name);
    
     if($MySQLi_CON->connect_errno)
     {
         die("ERROR : -> ".$MySQLi_CON->connect_error);
     }


?>



c)create a database
  • c1)create database testdb
  • c2)create a table users with userid ,username, password
  • c3)insert values 1,abc,123
    • INSERT INTO `testdb`.`users` (`userid`, `username`, `password`) VALUES ('1', 'abc', '123');
    
    
e)retreive values from db
//edit handle.php as
<?php
$username= $_POST['username'];
$password= $_POST['password'];


         $DB_host = "localhost";
         $DB_user = "root";
         $DB_pass = "123";
         $DB_name = "testdb";

         $MySQLi_CON = new MySQLi($DB_host,$DB_user,$DB_pass,$DB_name);
    
     if($MySQLi_CON->connect_errno)
     {
         die("ERROR : -> ".$MySQLi_CON->connect_error);
     }

        $query = $MySQLi_CON->query("SELECT userid, username, password FROM users WHERE username='$username'");

        $row=$query->fetch_array();

echo $row['password'];



?>
e2) compare values and print message 
//don't forget to close the db handle




version 2
===========================================================
klklkl;

a)Login Modification
  • add title
  • seperate signin and signup sections
  • add default value and remembering user choices
  • Add Registration Functionality
  • create a sign up here button with link to register.php
<!DOCTYPE HTML>
<head>
<title> Login and Registration System </title>
</head>
<body>
  <form method="post" action="handle.php">
    <input type="text" name="username" placeholder="Username" required/>
    <input type="password" name="password" placeholder="Password" required />
    <input type="submit" value="submit"/>
  </form>
<?php
echo "Sign Up Here<br/>";
?>
<button>
  <a href="register.php"> Sign Up Here </a>
</button>
</body>


b)create a home page—after successful login
  • alert on invalid login
    • alert('Username / Password Seems Wrong !');
  • redirect back to index.php
    • header("Location: index.php");
  • create home.php
    • header after echo will not work
  • introduction to the need for sessions
    • with an example –gmail
    • need for name in home page
  • need for logout page
    • logout.php
    • passing parameter with href
  • need for some styling
    • putting the login box inside a table
      • write index.php
        • <title>
        • <center>
<!DOCTYPE html>
<head>
	<title> Login </title>
</head>
<body>
	<center>
		<h1>hai</h1>
	</center>
</body>
  • form with table with 4 rows inside

  • one data in each item
    • Email
    • password
    • Login button
    • register button
<center>
		<form>
			<table>
				<tr>
					<td><input type="Text" placeholder="Your Email" required/></td>
				</tr>
				<tr>
					<td><input type="password" placeholder="Your Password" required/></td>
				</tr>
				<tr>
					<td><input type="submit" value="submit" /></td>
				</tr>
				<tr>
					<td><a href="" > Sign Up Here</td>
				</tr>
			</table>

		</form>

	</center>
  • align table to center
    • <table align="center" width="30%" border="0">

    • need for css
      • include a style sheet style.css
      • padding and margin for all elements
      • form
        • add id login-form for form element
        • margin-top:70px
      • table properties
border:solid #dcdcdc 1px;
padding:25px;
box-shadow: 0px 0px 1px rgba(0,0,0,0.2); //h-shadow v-shadow blur-amount color
  • table tr,td
    
		padding:15px;
		border:solid #e1e1e1 1px;
  • table tr td input
    • width:97%;
    • 	height:45px;
    • 	border:solid #e1e1e1 1px;
    • 	border-radius:3px;
    • 	padding-left:10px;
    • 	font-family:Verdana, Geneva, sans-serif;
    • 	font-size:16px;
    • 	background:#f9f9f9;
  • Edit this in index.php
    • <button type="submit" name="btn-login">Sign In</button>
    • 
      

    • time allowed------introduction to version 3

Version 3
===========
  • Page Layout
    • index.php
      • session start
      • if already login go to home.php
      • if submit button click perform query
      • html portion
    • home.php
      • session start
      • if session user not set go to index.php
      • else
      • html portion
        • logout link to
    • logout.php
      • session start
      • if session not set go to index.php
      • else if sessions set go to home.php
      • else if logout
    • dbconnect.php
      • establish connection
      • select database
    • style.css

Leave a comment