Home Upload Search Site news

PHP Message/comment system

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?
/* Riley's simple comment system */

$mainfile="main.html"; //Set this
$max= 10; //Set to 0 to disable

/*
  How to use this comment system:
 * Make a post form to this script with a message and name input
 * Put <!-- MESSAGES START --> at the beginning of the message area
 * Put <!-- MESSAGES END --> at the ending of the message area
 * For help contact me from my site http://rileyjamesbell.ml/
 */

function get_string_between($string, $start, $end){
    $string = ' ' . $string;
    $ini = strpos($string, $start);
    if ($ini == 0) return '';
    $ini += strlen($start);
    $len = strpos($string, $end, $ini) - $ini;
    return substr($string, $ini, $len);
}

foreach($_POST as $key => $val){
        $_POST[$key]= htmlspecialchars($val);
}
$_POST["message"]= nl2br($_POST["message"]);

$message= <<<EOF

<div class="message">
        <div class="messagecontent">
                <span class="name">{$_POST["name"]}</span>
                <blockquote>{$_POST["message"]}</blockquote>
        </div>
</div>
EOF;

$main= fopen($mainfile, "r") or die("Invalid write file!");
$maincontent= fread($main,filesize($mainfile));
fclose($main);

$messagearea= get_string_between($maincontent,"<!-- MESSAGES START -->","<!-- MESSAGES END -->");
$messages= array_reverse(explode("<!-- MESSAGE -->",$messagearea));

$messages[]= $message;
if($max&&count($messages)>$max)
        unset($messages[0]);

$html=explode("<!-- MESSAGES START -->",$maincontent)[0]."<!-- MESSAGES START -->";
$html.=implode("\n<!-- MESSAGE -->",array_reverse($messages));
$html.="<!-- MESSAGES END -->".explode("<!-- MESSAGES END -->",$maincontent)[1];

$main= fopen($mainfile, "w") or die("Invalid write file!");
fwrite($main, $html) or die("Cannot write to file! Check if permissions are 777");
fclose($main);

header("location: ".$mainfile);

Download [Show in hex viewer]
File URL:
Tags: No tags
Uploaded by: lolico
A simple message system used on my personal website at http://rileyjamesbell.ml/
CAPTCHA Image
Play CAPTCHA Audio
Refresh Image