Set normal user and Admin rights that he can use in PHP Programming
What is PHP Programming?
What is PHP programming? Well, in its most basic form, PHP is a programming language. It is a pretty widely used language and can be embedded into HTML, which is the big draw for anyone interested in web development. Where HTML can be long, with lots of commands, PHP pages contain HTML with embedded code, making it much easier to manage.
PHP stands for Hypertext Preprocessor, which, in itself is confusing. It is not actually as complicated as it seems though – if you have a basic understanding of HTML, PHP is going to be easy to learn. It allows you to collect process and utilize data to create output – it allows you to interact with all your pages.
Why choose PHP over JavaScript, then? The main difference between the two is that with JavaScript runs on the client (e.g. your browser) whereas PHP runs on your server, generating HTML, which is then sent to the client.
What Can PHP Do?
Server-side scripting – the main field for PHP. If you are an amateur practicing at home, this is the way to do it.
Command line scripting – ideal for scripts made using corn or Task Scheduler. Also great for simple text processing.
Writing desktop applications – PHP is probably not the best language to use to create desktop applications but for the advanced web developer, it provides you with many more options than its competitors.
What you need for PHP will generally be on your desktop. It can be used on all major operating systems (Linux, Windows and Mac OS X to name a few). PHP also supports many of the most widely used servers, meaning you will have the luxury of choice if you decide to use it.
Undoubtedly, the best thing about PHP is the fact that it is easy to pick up for complete novices, while having all of the advanced features that a seasoned professional could ask for. PHP’s abilities are not restricted to HTML either – you can produce anything from an image to flash movies.
Today we are going to build a registration system that keeps track of which users are admin and which are normal users. The normal users in our application are not allowed to access admin pages. All users (Admins as well as normal users) use the same form to login. After logging in, the normal users are redirected to the index page while the admin users are redirected to the admin pages.
Example
Code HTML
<html>
<body>
<form action="test.php" method="POST">
<div align="center">
<h1> User Login </h1>
<table>
<tr>
<th><Label> ID </label></th >
<th><input type="text" name="txtid" >
</tr>
<tr>
<th><Label> User Name </label></th>
<th><input type="text" name="txtusername">
</tr>
<tr>
<th><Label> Password </label></th>
<th><input type="password" name="txtpassword">
</tr>
<tr>
<th><Label> Permission </label></th>
<th><select name="puser">
<option value="1"> Admin </option>
<option Value="0"> User </option>
</select>
</th>
</tr>
<tr>
<th colspan="2"><input type="submit" value="Login" name="cmdLogin">
<input type="submit" value="Logout" name="cmdLogout"></th>
</table></div></form></body></html>
Code PHP
<?php
$server="localhost";
$username="root";
$password="";
$db="systemdatabase";
$conn=new mysqli($server,$username,$password,$db);
if($conn->connect_error)
{
    die("Connection Failed".$conn->connect_error());
}
if(isset($_POST['cmdLogin']))
{
   $id=$_POST['txtid'];
    $ida=$id;
    $username=$_POST['txtusername'];
    $usernamelogin=$username;
    $password=$_POST['txtpassword'];
    $passwordlogin=$password;
    $permission=$_POST['puser'];
   $permissionLogin=$permission;
$datatimelogin=date("y/m/d");
$sql="select *from userlogin where id='$id' and name='$username' and password='$password' and permission='$permission'";
$sql1="select *from userlogin where id='$id' and name='$username' and password='$password' and permission='$permission' and online=0";
$sql2="update userlogin set online=1 where id='$id' and name='$username' and password='$password' and permission='$permission'";
$sql3="insert into userdetail(id,Name,DateDetial)Values('$id','$username','$datatimelogin');";
$result=$conn->query($sql);
$result1=$conn->query($sql1);
if($result->num_rows>0)
{
if($result1->num_row>0)
{
    header("location:mainform.php");
    mysqli_query($conn,$sql2);
    mysqli_query($conn,$sql3);
}
elseif($result1->num_rows<=0)
{
    echo "Your Account Login other Device Please sign out your Device Other";
}}else{    echo "Unsuccessfully";}}
$conn->close();?>
Please Watching My Video is Below
No comments:
Post a Comment