Wednesday, 8 October 2014

facebook.com coding

function


<?php
session_start();
mysql_connect("localhost","root","");
mysql_select_db("login") or die("couldn't connect to db.");
?>




Index
<?php 

include_once("function.php");

if(isset($_POST['username']) && isset($_POST['password']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM users WHERE username='$username' AND pass='$password'";
$query  = mysql_query($sql);
$num_rows = mysql_num_rows($query);
if($num_rows >= 1)
{
$_SESSION['registered'] = 'sdfds';
header("Location: dashboard.php");

}else
{
$_SESSION['dontexist'] = 'dsfds';
}
}


if(isset($_POST['user']))
{
$username = $_POST['user'];
$password = $_POST['password'];

$sql = "SELECT * FROM users WHERE username='$username'";
$query  = mysql_query($sql);
$num_rows = mysql_num_rows($query);
if($num_rows >= 1)
{
//alert('sdfsd');
$_SESSION['user_exist'] = 'dfds';
}else
{
$sql = "INSERT INTO users VALUES (NULL, '$username', '$password')";
mysql_query($sql);
$_SESSION['user_registerd'] = 'fg';
header("Location: dashboard.php");
}


}

?>


<form action="" method="post">
Email Address <input type="text" name="username">
    <span>Password</span>
    <input type="password" name="password" id="">
    <input type="submit" value="Login">
</form>
<?php

if(isset($_SESSION['dontexist']))
{
echo '<p style="color:red;">Please check Your user name and password.</p>';
unset($_SESSION['dontexist']);
}
 ?>



<h3>REgisration foerm</h3>
<table border="1" width="350">
<tr>
<form action="" method="post">
<td>Email</td><td>
<input type="text" name="user">
    </td>
</tr>
<tr>
<td>Password</td>
<td>

    <input type="password" name="password" id=""> <br>
    </td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Submit">
</td>
</tr>
</form>
</table>
<?php

if(isset($_SESSION['user_exist']))
{
echo '<p style="color:red;">This username is aalready exit.</p>';
unset($_SESSION['user_exist']);
}
 ?>






Dashbord


<?php
include_once("function.php");


if(!isset($_SESSION['registered']))
{
header("Location: index.php");
}

if(isset($_SESSION['user_registerd']))
{
echo '<p style="color:red;">Thank you</p>';
unset($_SESSION['user_registerd']);
}
?>
User dashboard  <a href="logout.php">logout</a>




Logout
<?php
include_once("function.php");

unset($_SESSION['registered']);
header("Location: index.php");

No comments:

Post a Comment