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");
}
?>
Good post friend @dapeeyg
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
thank you
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
yes, I am happy to follow your footsteps
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
am glad to hear that, thank you
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
yes, i like to follow your step @dapeeyg
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I see you've done a great job here! But instead of going through the long hassle of procedural programming which is prone to errors, and relatively uneasy to maintain codebase, I think switching to object oriented style of programming would be more profitable!
PHP has advanced from the old mysqli ways to PDOs now, and as developers in this modern age, we need to start adopting these new trends.
Between, thanks for sharing this! It sure would come in handy to someone that has been having problems!
nice one...PHP!!!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Good article. Simple to understand. I agree that OOP would make the code even more easier to follow and maintain, especially if more lines of code were to be added. Another thing, HTML is more forgiving but it is a good practice to keep track of all tags. It seems a lot of the
<li>
tags were not closed. That can lead to issues with some JS libraries down the road. Good thing is that modern web-browsers can 'fix' that still display the UI correctly.Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
thanks. I stick to what i know best and also source for ways on improving and doing it better.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
one of the really important issues. I can thank you for a successful sharing and everyone's name
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
thanks bro
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit