By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 1,964 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

Pointing out two bunches of code from a php script

P: 14
As the solution.. I have got this script code.. it's an open source so i can modify it..

The problem is it's a guest book script written in very highly and deeply php language that I am not able to understand all..
BUT I am here you guys can read and help me..

From this script i would need your help, You will have to separate 2 things <PLEASE>

1. Bunch of code, Which writes message and gives a unique id to each entry...SO identified while want to delete..

2. BUNCH of code, by which we get a text linked as file.php?admin=delete&msg=(MESSAGE ID).

Please help friends... I need your help really... I am looking forward for help..[php]<?php
define('ADMIN_PASS', '123');
function strip_chars($var)
{
return trim(str_replace("\r", NULL, htmlspecialchars(stripslashes(strip_tags($var)), ENT_QUOTES)));
}
function bbcode($var)
{
$var = preg_replace('/http:\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%%&\/~\+#])?/i', '<a href="$0">$0</a>', $var);
$var = preg_replace('(\[b\](.+?)\[\/b\])is', '<b>$1</b>', $var);
$var = preg_replace('(\[i\](.+?)\[\/i\])is', '<i>$1</i>', $var);
$var = preg_replace('(\[u\](.+?)\[\/u\])is', '<u>$1</u>', $var);
return trim($var);
}
if (isset($_POST['password']))
{
$password = md5($_POST['password']);
if ($password == md5(ADMIN_PASS))
{
setcookie('password', $password);
}
}
else
{
$password = isset($_COOKIE['password']) ? $_COOKIE['password'] : NULL;
}
if (isset($_GET['admin']) && $_GET['admin'] == 'logout')
{
setcookie('password', '');
unset($_COOKIE['password'], $password);
header("Location: ".$_SERVER['PHP_SELF']);
exit;
}
else
if (isset($_GET['admin']) && $_GET['admin'] == 'delete')
{
if ($password == md5(ADMIN_PASS))
{
if ($file = fopen('./betadb.txt', 'r'))
{
$data = '';
while (!feof($file))
{
$line = fgets($file, 4096);
list($timestamp) = explode(chr(02), trim($line));
if ($timestamp == $_GET['msg'])
{
$data .= fread($file, filesize('./betadb.txt'));
fclose($file);
if (!$file = fopen('./betadb.txt', 'w'))
{
break;
}
fwrite($file, $data);
fclose($file);
break;
}
else
{
$data .= $line;
}
}
}
}
header("Location: ".$_SERVER['PHP_SELF']);
exit;
}
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$_POST = str_replace(chr(02), ' ', $_POST);
$ip = $_SERVER['REMOTE_ADDR'];
$name = strip_chars($_POST['name']);
$subject = strip_chars($_POST['subject']);
$email = strip_chars($_POST['email']);
$website = strip_chars($_POST['website']);
$message = str_replace("\n", "<br>", strip_chars($_POST['message']));
$message = bbcode($message);
$timestamp = time();
if (!(empty($name) || empty($message)))
{
$file = fopen('./betadb.txt', 'a+');
$data = $timestamp . chr(02) . $name . chr(02) . $subject . chr(02) . $email . chr(02) . $website . chr(02) . $message . chr(02) . $ip . "\n";
fwrite($file, $data);
fclose($file);
}
header("Location: ".$_SERVER['PHP_SELF']);
exit;
}
?>
<html>
<head>
<title>Fsoft Beta Testing</title>
<style type="text/css">
body
{
background-color: #FFFFFF;
color: #125EC6;
}
td
{
font-family: Arial;
color: #125EC6;
font-size: 13px;
}
input, textarea
{
background-color: #FFFFFF;
color: #125EC6;
font-size: 13px;
border-style: solid;
border-width: 1px;
border-color: #125EC6;
}
p.title
{
font-family: Arial;
font-size: 19px;
color: #0F448E;
font-weight: bold;
}
.banner
{
font-family: Arial;
font-size: 13px;
background-color: #ABCAF6;
color: #0F448E;
font-weight: bold;
}
.message
{
font-family: Arial;
font-size: 13px;
background-color: #E0EBFB;
color: #125EC6;
}
a:link, a:visited
{
color: #125EC6;
}
a:hover
{
color: #125EC6;
}
</style>
</head>
<body>
<?php
if (isset($_GET['admin']))
{
if ($_GET['admin'] == 'login')
{
echo "<center>\n";
echo "<p class=\"title\">Guestbook login</p>\n";
echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\"><p><input type=\"password\" name=\"password\" size=\"20\" /> <input type=\"submit\" value=\"Login\" name=\"submit\" /></p></form>\n";
echo "</center>\n";
}
}
else
{
echo "<p align=\"center\" class=\"title\">Fsoft Beta Testing</p>\n";
if ($password != md5(ADMIN_PASS))
{
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n";
echo "<table width=\"100%\" style=\"background-color:#C3D9F8;\">\n";
echo " <tr>\n";
echo " <td width=\"67\">Name:</td>\n";
echo " <td><input type=\"text\" value=\"\" name=\"name\" style=\"width:100%;\"/></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td>Message; </td>\n";
echo " <td><textarea name=\"message\" rows=\"3\" style=\"width:100%;\"></textarea></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td></td>\n";
echo " <td><input type=\"submit\" name=\"Submit\" value=\"Submit!\"/>";
echo "<input type=\"reset\" value=\"Reset\"/>";
echo "</td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "</form>\n";
}

if(filesize('./betadb.txt') == 0)
{
echo "<font style=\"font-family:Arial;color:#125EC6;font-size:13px;\">No posts found.<br></font>\n";
}
else
{
$items = file('./betadb.txt');
$items = array_reverse($items);
str_replace("<", "&lt;", $items);
str_replace(">", "&gt;", $items);
str_replace("\n", "<br>\n", $items);
foreach($items as $line)
{
list($timestamp, $name, $subject, $email, $website, $message, $ip) = explode(chr(02), trim($line));
$topic = "\n<div class=\"banner\">";
$topic .= date('m/d/Y H:i:s',$timestamp) . " ";
if ($email != "")
{
$topic .= "<a href=\"mailto:$email\">";
}
$topic .= "$name";
if ($email != "")
{
$topic .= "</a>";
}
if ($website != "")
{
$website = eregi_replace("^http://", "", $website);
$topic .= " (<a href=\"http://$website\" target=\"_blank\">$website</a>) - ";
}
else
{
$topic .= " - ";
}
$topic .= "$subject</div>\n";
$topic .= "<div class=\"message\">$message</div>\n";
echo $topic;
if ($password == md5(ADMIN_PASS))
{
echo "<div class=\"banner\"><a href=\"".$_SERVER['PHP_SELF']."?admin=delete&amp;msg=$timestamp\">[delete]</a> <a href=\"http://whois.sc/".$ip."\" target=\"_blank\" title=\"".$ip."\">[whois]</a></div>\n";
}
echo "<br>\n";
}
}
echo "<br>\n";
if ($password == md5(ADMIN_PASS))
{
echo "<a href=\"".$_SERVER['PHP_SELF']."?admin=logout\"><font style=\"font-family:Arial;color:#125EC6;font-size:13px;\">Logout</a><br></font>\n";
}
else
{
echo "<a href=\"".$_SERVER['PHP_SELF']."?admin=login\"><font style=\"font-family:Arial;color:#125EC6;font-size:13px;\">Admin login</a><br></font>\n";
}
}
?>
</body>
</html>[/php]Thanks in advance..

FAISAL!
Apr 3 '08 #1
Share this Question
Share on Google+
3 Replies


Markus
Expert 5K+
P: 6,050
If you're not going to use code tags (you've been around long enough) then i dont think there's anyone whos going to try and sort that code for you.

What you've asked isn't even a question - it's just a request.

Regards.
Apr 3 '08 #2

ronverdonk
Expert 2.5K+
P: 4,258
warning: You have been around this forum long enought to knowm that you have to enclose your posted code in [code] tags (See How to Ask a Question).

Please use [code] tags in future.

MODERATOR
Apr 4 '08 #3

ronverdonk
Expert 2.5K+
P: 4,258
markus is quite correct. This is not a problem that you encountered or a question that came up during the development of your code. You just copied, with permission, somebody else's code (without any comment or explanation in it) for you to adapt and now you just expect our forum members to fix it for you because it is too deep.

As I have said on many posts: this forum is not a code factory or a code-on-demand development center.

There are plenty of members with real problems and questions regarding their own code.

Ronald
Apr 4 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.