Codice PHP:
<?php
session_start();
require_once('lib/Users.class.php');
$login = New Users;
$login->access_denied();
$adminpassword = 'admin';
error_reporting(E_ALL ^ E_NOTICE);
$ipbans = array();
if((isset($_GET['admin']) && $_GET['admin'] == 1) || isset($_POST['admin']) && $_POST['admin'] == 1)
{
if(!isset($_GET['adminpass']) && !isset($_POST['adminpass']))
{
echo 'Please enter the admin password.';
echo '<form action="action.php" method="get">
<input type="password" name="adminpass"/>
<input type="hidden" name="admin" value="1"/>
<input type="submit" value="Continue" />
</form>
</body>
</html>';
}
elseif($_GET['adminpass'] == $adminpassword || $_POST['adminpass'] == $adminpassword)
{
$data = unserialize(file_get_contents('data.txt'));
$data = array_reverse($data);
if(isset($_POST['edit']) && isset($_POST['message']))
{
$data[$_POST['edit']]['message'] = $_POST['message'];
file_put_contents('data.txt', serialize($data));
header("Location: action.php?admin=1&adminpass={$_POST['adminpass']}");
}
elseif(isset($_GET['edit']))
{
echo '<strong>Editing comment id '.$_GET['edit'].'
<form action="action.php" method="POST">
<textarea name="message" rows="6" cols="38">
'.$data[$_GET['edit']]['message'].'
</textarea>
<input type="hidden" name="edit" value="'.$_GET['edit'].'"/>
<input type="hidden" name="admin" value="1"/>
<input type="hidden" name="adminpass" value="'.$_GET['adminpass'].'"/>
<input type="submit" value="Submit"/>
</form>
<br/>
<br/>';
}
elseif(isset($_GET['delete']))
{
unset($data[$_GET['delete']]);
file_put_contents('data.txt', serialize(array_reverse($data)));
header("Location: action.php?admin=1&adminpass={$_GET['adminpass']}");
}
elseif(isset($_GET['banuser']))
{
$bannedusers = unserialize(file_get_contents('userbans.txt'));
if(!isset($bannedusers))
$bannedusers = array();
array_push($bannedusers, $_GET['banuser']);
file_put_contents('userbans.txt', serialize($bannedusers));
}
elseif(isset($_GET['banip']))
{
$bannedips = unserialize(file_get_contents('ipbans.txt'));
array_push($bannedips, $_GET['banip']);
file_put_contents('ipbans.txt', serialize($bannedips));
}
echo '<strong>Moderate Comments</strong>
<table width="100%">';
$c = 0;
for($i = 0; $i < count($data); $i++)
{
$date = date("F j, Y, g:i a", $data[$i]['date']);
$user = htmlspecialchars(stripslashes($data[$i]['user']));
$message = htmlspecialchars(stripslashes($data[$i]['message']));
$ip = $data[$i]['ip'];
if(isset($data[$i]['website']) && !empty($data[$i]['website']))
{
$website = htmlspecialchars(stripslashes($data[$i]['website']));
$user = "<a href="$website">$user</a>";
}
if($c == 0)
{
$c1 = '#d4e24f';
$c2 = '#d4e24f';
$c = 1;
}
else
{
$c1 = '#d4e24f';
$c2 = '#d4e24f';
}
if($data[$i]['user'] != '11jds83jd7')
{
echo"<tr><td width="200" valign="top" style="background-color: $c1"><strong>$user</strong><br/>IP: $ip<br/>$date</td><td valign="top" style="background-color: $c2">$message</td><td style="background-color: $c2"><a href="guestbook.php?admin=1&adminpass={$_GET['adminpass']}&edit=$i">Edit</a><br><a href="guestbook.php?admin=1&adminpass={$_GET['adminpass']}&delete=$i">Delete</a></tr>\n";
}
};
if(count($data) == 0)
{
echo '<tr><td colspan="2"><strong>There are no posts to display.</strong><br/><br/></td></tr>';
}
echo '</table>';
?>