Post: [PHP] Login script + whitelist manager.
05-10-2011, 12:49 AM #1
(adsbygoogle = window.adsbygoogle || []).push({});
Originally posted by 039

This is my whitelist editor script. To use it you will need to create a database and edit the settings.

*NOTE*
There is NO password encryption as of yet (i need to learn how)

This is NOT complete, therefore will not work out of the box as an actual whitelist editing script for minecraft, just thought i'd share my progress.

index.php
    
<html>
<?php
session_start();
if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == 1)
echo "<meta http-equiv=\"REFRESH\" content=\"0;url=member.php\">";
else {
echo "
<table width=\"300px\" border=\"0px\">
<form action=\"login.php\" method=\"post\">
<tr><td>Name:</td> <td><input type=\"text\" name=\"username\" /></td></tr>
<tr><td>Password:</td> <td><input type=\"password\" name=\"password\" /></td></tr>
<tr><td><input type=\"hidden\" name=\"submitted\" value=\"1\"></td>
<td><input type=\"submit\" value=\"Login\" /></td></tr>
</form>
</table>";
}
?>
</html>



login.php
    
<?php
include('include/dbcon.inc.php'Winky Winky;
include('func/postget.php'Winky Winky;
include('AES/AES.class.php'Winky Winky;
include('AES/AES.settings.php'Winky Winky;

$aes = new AES($aesKey);

session_start();

$username = postData('username'Winky Winky;
$password = $aes->encrypt(postData('password'Winky Winky);
$_SESSION['submitted'] = postData('submitted'Winky Winky;

if ($_SESSION['submitted'] == 0)
echo "<meta http-equiv=\"REFRESH\" content=\"0;url=index.php\">";
else {

$result = mysql_query("SELECT * FROM users
WHERE username='$username'");

while ($row = mysql_fetch_array($result)) {
if ($username == $row['username'] && $password == $row['password']) {
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['userid'] = $row['ID'];
$_SESSION['loggedin'] = 1;

}
}
}
?>
<html>
<meta http-equiv="REFRESH" content="0;url=member.php">
</html>


member.php
    
<html>
<?php

session_start();

if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == 1){
echo "
<form action=\"action.php\" method=\"post\">
<select name=\"action\">
<option value=\"addList\" selected>Add to list</option>
<option value=\"viewList\">View Whitelist</option>
<option value=\"deleteList\">Awesome faceelete Whitelist</option>
<option value=\"logout\">Logout</option>
</select>
<input type=\"submit\" value=\"Send\" />
<br />
<input type=\"text\" name=\"username\" value=\"\" /> <b>Use if adding to whitelist</b>
</form> ";

} else if($_SESSION['submitted'] == 1)
echo "Left at least one field blank";
else if ($_SESSION['submitted'] == 0)
echo "<meta http-equiv=\"REFRESH\" content=\"0;url=index.php\">";
else
echo "You don't have permissions to view this page";
?>
<br />
<a href="../TEST/index.php">Back</a>
</html>


action.php
    
<?php

include('func/postget.php'Winky Winky;
session_start();
switch(postData('action'Winky Winky) {
case "addList":
$username = postData('username'Winky Winky;
if($username == "")
echo "No input";
else {
$file=fopen("whitelist.txt","a");
fwrite($file, $username . "\n");
echo "Member " . $username . " added to the whitelist!";
}
break;

case "viewList":
echo "<iframe width=\"300px\" height=\"500px\" src=\"whitelist.txt\"></iframe>";
break;

case "deleteList":
$myFile = "whitelist.txt";
unlink($myFile);
echo $myFile . " deleted!";
break;

case "logout":
if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == 1) {
unset($_SESSION['username']);
unset($_SESSION['password']);
unset($_SESSION['loggedin']);
unset($_SESSION['submitted']);
session_destroy();
session_start();
$_SESSION['submitted'] = 0;
echo "Logged out!";
} else {
echo "Not logged in!";
}
break;
}
?>
<html>
<br />
<a href="../TEST/member.php">Back</a>


include/dbcon.inc.php
    
<?php
include('settings/db.php'Winky Winky;
$con = mysql_connect($dbHostname, $dbUsername, $dbPassword);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbDatabase, $con);
?>


settings/db.php
    
<?php
//Server hostname (usually localhost)
$dbHostname = "localhost";
//MySQL username
$dbUsername = "root";
//MySQL password
$dbPassword = "";
//Database name
$dbDatabase = "login";
?>


func/postget.php
    
<?php
function getData($var, $maxLength=99) {
$value = NULL;
if (isset($_GET[$var])) {
$value = trim(htmlentities($_GET[$var], ENT_QUOTES));
if (strlen($value) > $maxLength) {
$value = substr($value, 0, $maxLength);
}
}
return $value;
}

function postData($var, $maxLength=99) {
$value = NULL;
if (isset($_POST[$var])) {
$value = trim(htmlentities($_POST[$var], ENT_QUOTES));
if (strlen($value)>$maxLength) {
$value = substr($value, 0, $maxLength);
}
}
return $value;
}
?>



EDIT in 'func/postget.php' the $maxlength=99 should be $maxlength=9999 (for some reason it gets shortened)


source You must login or register to view this content.
(adsbygoogle = window.adsbygoogle || []).push({});

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo