I thought sharing this will help people who has passion for programming, i will be sharing some php codes that you can use to link up your sign up and login page when developing a full, well functional website.
1. The php code for a standard signup page;
- step 1: copy the code below into a notepad++, so that you can edit before you can make use of it.
<?php
require('includes/config.php');
if(!empty($_POST))
{
$msg="";
if(empty($_POST['firstname']) || empty($_POST['username']) || empty($_POST['gender']) || empty($_POST['password']) || empty($_POST['confirmpassword']) || empty($_POST['email'])||empty($_POST['city']))
{
$msg.="<li>Please full fill all requirement";
}
if($_POST['password']!=$_POST['confirmpassword'])
{
$msg.="<li>Please Enter your Password Again.....";
}
if(!ereg("^[a-z0-9_]+[a-z0-9_.]*@[a-z0-9_-]+[a-z0-9_.-]*\.[a-z]{2,5}$",$_POST['mail']))
{
$msg.="<li>Please Enter Your Valid Email Address...";
}
if(strlen($_POST['password'])>10)
{
$msg.="<li>Please Enter Your Password in limited Format....";
}
if(is_numeric($_POST['firstname']))
{
$msg.="<li>Name must be in String Format...";
}
if($msg!="")
{
header("location:register.php?error=".$msg);
}
else
{
$firstname=$_POST['firstname'];
$username=$_POST['username'];
$password=$_POST['password'];
$gender=$_POST['gender'];
$email=$_POST['mail'];
$contact=$_POST['contact'];
$city=$_POST['city'];
$query="insert into user(u_firstname,u_username,u_password,u_gender,u_email,u_contact,u_city)
values('$firstname','$username','$password','$gender','$email','$contact','$city')";
mysqli_query($conn,$query) or die("Can't Execute Query...");
header("location:register.php?ok=1");
}
}
else
{
header("location:index.php");
}
?>
2. For the login page, follow the same instruction above and you will thank me later
<?php session_start();
require('includes/config.php');
if(!empty($_POST))
{
$msg="";
if(empty($_POST['username']))
{
$msg[]="No such User";
}
if(empty($_POST['password']))
{
$msg[]="Password Incorrect........";
}
if(!empty($msg))
{
echo '<b>Error:-</b><br>';
foreach($msg as $k)
{
echo '<li>'.$k;
}
}
else
{
$username=$_POST['username'];
$q="select * from user where u_username='$username'";
$res=mysqli_query($conn,$q) or die("wrong query");
$row=mysqli_fetch_assoc($res);
if(!empty($row))
{
if($_POST['password']==$row['u_password'])
{
$_SESSION=array();
$_SESSION['username']=$row['u_username'];
$_SESSION['uid']=$row['u_pwd'];
$_SESSION['status']=true;
if($_SESSION['username']!="admin")
{
header("location:index.php");
}
else
{
header("location:admin/index.php");
}
}
else
{
echo 'Incorrect Password....';
}
}
else
{
echo 'Invalid User';
}
}
}
else
{
header("location:index.php");
}
?>