Results 1 to 2 of 2

Thread: Login / register

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2016
    Posts
    9

    Login / register

    Hello,

    I'm using this code for my login system and was wondering if anyone can help me add an admin link if a user logs in as admin using a status field then it will show Admin link and if they login as a user if will disable link if will need to show on the Dashboard Page.

    Register.php

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Registration</title>
    <link rel="stylesheet" href="css/style.css" />
    </head>
    <body>
    <?php
    require('db.php');
    // If form submitted, insert values into the database.
    if (isset($_REQUEST['username'])){
            // removes backslashes
    	$username = stripslashes($_REQUEST['username']);
            //escapes special characters in a string
    	$username = mysqli_real_escape_string($con,$username); 
    	$email = stripslashes($_REQUEST['email']);
    	$email = mysqli_real_escape_string($con,$email);
    	$password = stripslashes($_REQUEST['password']);
    	$password = mysqli_real_escape_string($con,$password);
    	$trn_date = date("Y-m-d H:i:s");
            $query = "INSERT into `users` (username, password, email, trn_date)
    VALUES ('$username', '".md5($password)."', '$email', '$trn_date')";
            $result = mysqli_query($con,$query);
            if($result){
                echo "<div class='form'>
    <h3>You are registered successfully.</h3>
    <br/>Click here to <a href='login.php'>Login</a></div>";
            }
        }else{
    ?>
    <div class="form">
    <h1>Registration</h1>
    <form name="registration" action="" method="post">
    <input type="text" name="username" placeholder="Username" required />
    <input type="email" name="email" placeholder="Email" required />
    <input type="password" name="password" placeholder="Password" required />
    <input type="submit" name="submit" value="Register" />
    </form>
    </div>
    <?php } ?>
    </body>
    </html>
    Login.php

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Login</title>
    <link rel="stylesheet" href="css/style.css" />
    </head>
    <body>
    <?php
    require('db.php');
    session_start();
    // If form submitted, insert values into the database.
    if (isset($_POST['username'])){
            // removes backslashes
    	$username = stripslashes($_REQUEST['username']);
            //escapes special characters in a string
    	$username = mysqli_real_escape_string($con,$username);
    	$password = stripslashes($_REQUEST['password']);
    	$password = mysqli_real_escape_string($con,$password);
    	//Checking is user existing in the database or not
            $query = "SELECT * FROM `users` WHERE username='$username'
    and password='".md5($password)."'";
    	$result = mysqli_query($con,$query) or die(mysql_error());
    	$rows = mysqli_num_rows($result);
            if($rows==1){
    	    $_SESSION['username'] = $username;
                // Redirect user to index.php
    	    header("Location: index.php");
             }else{
    	echo "<div class='form'>
    <h3>Username/password is incorrect.</h3>
    <br/>Click here to <a href='login.php'>Login</a></div>";
    	}
        }else{
    ?>
    <div class="form">
    <h1>Log In</h1>
    <form action="" method="post" name="login">
    <input type="text" name="username" placeholder="Username" required />
    <input type="password" name="password" placeholder="Password" required />
    <input name="submit" type="submit" value="Login" />
    </form>
    <p>Not registered yet? <a href='registration.php'>Register Here</a></p>
    </div>
    <?php } ?>
    </body>
    </html>
    Dashboard.php

    Code:
    <?php
    require('db.php');
    include("auth.php");
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Dashboard - Secured Page</title>
    <link rel="stylesheet" href="css/style.css" />
    </head>
    <body>
    <div class="form">
    <p>Dashboard</p>
    <p>This is another secured page.</p>
    <p><a href="index.php">Home</a></p>
    <a href="logout.php">Logout</a>
    </div>
    </body>
    </html>

    Thanks



    Mark

  2. #2

    Thread Starter
    New Member
    Join Date
    Aug 2016
    Posts
    9

    Re: Login / register

    Can anyone help please?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width