Forum Tutorial - MOTD and Banning Messages
Submitted by Yorkiebar on Saturday, March 8, 2014 - 08:49.
Introduction:
This tutorial is going to be covering message of the days and banning messages.
Database Setup:
First we are going to set the database up ready for storing our information, create a new table named "reasons", then give it the following columns of structure:
id - INT - 5 Length - Primary Key - Auto Increment (AI/A_I)
use - VARCHAR - 255 Length
message - VARCHAR - 255 Length
additional - VARCHAR - 255 Length
We are going to make the use value "motd" for Message of the Day, or "ban" for the banning message. While we use the additional slot to hold the username for banning messages.
Banning Messages:
Next we are going to add a banning message option to the banning form of the admin panel...
Next we will alter our processing to add the banning reason to our new table...
Finally we need to output the message to the user once they try to login, but they're banned...
Message Of The Day:
Next we add a message of the day option to the admin panel...
Next we process the information. If there is already an motd, we update it, otherwise we insert a new row to create one...
Finally we show the motd on the homepage...
- echo '<tr><td>'.$row["username"].'</td><td>Current Level: '.$row["level"].'</td><td>Change Level: </td><td><form action="admin.php?act=level&uID='.$row["id"].'" method="POST"><input type="number" name="newLevel" /><input type="submit" value="Change User Level" /></form></td><td><form action="admin.php?act=ban&uID='.$row["id"].'" method="POST"><input type="text" name="message" /><input type="submit" value="Ban User!" /></form></td><td><form action="admin.php?act=unban&uID='.$row["id"].'" method="POST"><input type="submit" value="Unban User!" /></form></td></tr>';
- $uID = $_GET['uID'];
- //User exists, set level to 0 and ban them.
- if ($banUserQuery) {
- $banMessage = $_POST['message'];
- $banUser = $banUserInfo['username'];
- $insertReasonQ = mysqli_query($con, "INSERT INTO `reasons` VALUES ('', 'ban', '$banMessage', '$banUser')");
- if ($insertReasonQ)
- echo 'Banned user.';
- }else
- echo 'Failed to ban user...';
- }
- }
- $pass = $_POST['pass'];
- $user = $_POST['user'];
- if ($info['level'] != '0') {
- $storedPassword = $info['password'];
- if ($storedPassword == $passMD5) {
- $_SESSION['username'] = $user;
- if ($info['level'] == 2)
- $_SESSION['isMod'] = 'yes';
- if ($info['level'] == 3)
- $_SESSION['isAdmin'] = 'yes';
- echo 'Logged in!';
- }else
- echo 'Password was incorrect. Please try again.';
- }else{
- $banReasonQ = mysqli_query($con, "SELECT * FROM `reasons` WHERE `additional`='$user' AND `use`='ban'") or die(mysql_error());
- $banReason = $banReasonInfo['message'];
- echo 'That account is banned!<br/>Reason: '.$banReason;
- }
- }else
- echo 'That username was not found. Please try again.';
- }
- <form action='admin.php?act=motd' method='POST'>
- Current MOTD: <?php
- $motdQ = mysqli_query($con, "SELECT * FROM `reasons` WHERE `use`='motd'");
- if (mysqli_num_rows($motdQ) > 0) {
- $motdInfo = mysqli_fetch_array($motdQ);
- echo $motdInfo['message'];
- }
- ?>
- <br/>
- Update MOTD: <input type='text' name='newMOTD' />
- </form>
- $message = $_POST['newMOTD'];
- echo 'MOTD Updated.';
- }else{
- if ($motdInsert) {
- echo 'Inserted motd.';
- }else
- echo 'Failed to insert motd.';
- }
- }
- <?php
- echo '<h1>MOTD:</h1><br/>'.$motdInfo['message'];
- }
- ?>
Add new comment
- 39 views