Jump to content

Admin login page


vaidoshia

Recommended Posts

Hello, I am trying to make a code for admin login, however, when I upload a page and try to enter password and username, I cannot go to another page. Please let me know what is the problem with my code. Thank u.

 

 

This is the actual login page code:

 

<?php require_once("includes/session.php"); ?>

<?php require_once("includes/connection.php"); ?>

<?php

 

if (logged_in()) {

redirect_to("staff.php");

}

 

include_once("includes/form_functions.php");

 

// START FORM PROCESSING

if (isset($_POST['submit'])) { // Form has been submitted.

$errors = array();

 

// perform validations on the form data

if(empty($_POST['username'])) {$errors[]='FORGOT';}

else {$username = mysqli_real_escape_string($connection, trim(stripslashes($_POST['username']))); ;}

 

if(empty($_POST['hashed_password'])) {$errors[]='FORGOT';}

else {$hashed_password = mysqli_real_escape_string($connection, trim(stripslashes($_POST['hashed_password']))); ;}

 

 

if ( empty($errors) ) {

// Check database to see if username and the hashed password exist there.

if(empty($errors)) {

$query = "SELECT * FROM users WHERE (username = '$username' AND hashed_password = '$hashed_password')";

$query = @mysqli_query ($connection, $query);

 

if(@mysqli_num_rows($query) == 1)

{

$row = mysqli_fetch_array ($query, MYSQLI_ASSOC);

return array (true, $row);}

 

// username/password authenticated

// and only 1 match

$found_user = mysqli_fetch_array($result_set);

$_SESSION['user_id'] = $found_user['id'];

$_SESSION['username'] = $found_user['username'];

redirect_to("staff.php");

 

} else {

// username/password combo was not found in the database

$message = "Username/password combination incorrect.<br />

Please make sure your caps lock key is off and try again.";

}

} else {

if (count($errors) == 1) {

$message = "There was 1 error in the form.";

} else {

$message = "There were " . count($errors) . " errors in the form.";

}

}

 

} else { // Form has not been submitted.

$username = "";

$password = "";

}

?>

<?php include("includes/header.php"); ?>

<table id="structure">

<tr>

<td id="navigation">

<a href="index.php">Return to public site</a>

</td>

<td id="page">

<h2>Staff Login</h2>

<?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>

<?php if (!empty($errors)) { display_errors($errors); } ?>

<form action="admin.php" method="post">

<table>

<tr>

<td>Username:</td>

<td><input type="text" name="username" maxlength="30" /></td>

</tr>

<tr>

<td>Password:</td>

<td><input type="password" name="hashed_password" maxlength="30"/></td>

</tr>

<tr>

<td colspan="2"><input type="submit" name="submit" value="Login" /></td>

</tr>

</table>

</form>

</td>

</tr>

</table>

<?php include("includes/footer.php"); ?>

 

This is my session include file:

<?php

session_start();

 

function logged_in() {

return isset($_SESSION['user_id']);

}

 

function confirm_logged_in() {

if (!logged_in()) {

redirect_to("admin.php");

}

}

?>

This is my function include file:

 

<?php

// This file is the place to store all basic functions

 

function mysqli_rum_rows($result_set) {

if (!$result_set) {

die("Database query failed: " . mysqli_error());

}

}

 

?>

 

Thank you in advance!

Link to comment
Share on other sites

Nothing is going to sink in completely unless you go through the whole process yourself.

 

Luckily there some free video tutorials on the forum.

 

http://www.killersites.com/community/index.php?/topic/4525-php-login-training-tutorial-–-part-1/

 

It's not a full complete series of the php login system but it should help you on your way to understanding the process.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...