berichten-balk-met-post-beveiliging

Gesponsorde koppelingen

PHP script bestanden

  1. berichten-balk-met-post-beveiliging

« Lees de omschrijving en reacties

MySQL:
------- berichten balk---------
CREATE TABLE `berichtenbalk` (
`id` int(11) NOT NULL auto_increment,
`naam` varchar(50) NOT NULL default '',
`bericht` varchar(50) NOT NULL default '',
`ip` varchar(15) NOT NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM;

---beveiliging-----

CREATE TABLE `bericht` (
`id` INT(100) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`ip` VARCHAR(12) NOT NULL,
`aant` INT(2) DEFAULT '0' NOT NULL,
UNIQUE (`ip`)
);

-------smilys (optioneel)------
CREATE TABLE `smilies` (
`smilieid` int(6) NOT NULL auto_increment,
`smilietext` varchar(5) NOT NULL default '',
`smilie` varchar(30) NOT NULL default '',
PRIMARY KEY (`smilieid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


------balk.php------

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?php
include ("config.php");
?>

<?
function smilie($text) {
  
  $textresult = mysql_query("SELECT smilietext FROM smilies");
  $imageresult = mysql_query("SELECT smilie FROM smilies");
  $textrows = mysql_num_rows($textresult);
  
  for ($i = 0; $list = mysql_fetch_array($textresult); $i++) {
    $patterntext["$i"] = "/$list[smilietext]/";
  }

  
  for ($i = 0; $list = mysql_fetch_array($imageresult); $i++) {
    $patternimage["$i"] = "<img src=\"" . $list[smilie] . "\">";
  }

  
  if ($textrows > '0') {
    $text = preg_replace($patterntext, $patternimage, $text);
  }


  return $text;
}

?>

<SCRIPT>
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=300,left = 362,top = 209');");
}
</script>
<?
echo "<marquee width=70% style=\"cursor: default\" onmouseover=\"this.stop()\" onmouseout=\"this.start()\">";

$query = mysql_query("SELECT * FROM berichtenbalk ORDER BY id DESC LIMIT ".$hoeveel) or die (mysql_error());
 
while ($obj = mysql_fetch_object($query)) {
   $naam = htmlspecialchars($obj->naam);
   $bericht = htmlspecialchars($obj->bericht);
   $bericht = smilie($bericht);  

   echo "<b>".$naam."</b>: ".$bericht." ".$teken;  //tonen van de berichten
}

echo "</marquee><br>";

?>

<a href="javascript:popUp('toevoegen.php')"  TITLE="Ook een bericht plaatsen? Klik HIER!!">Bericht plaatsen</a>
<br>


------toevoegen.php--------------
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
59
60
61
62
63
64
65
66
67
68
69
<script>
function emoticon(text) {
    text = '' + text + '';
    if (document.berichtenbalk.bericht.createTextRange && document.berichtenbalk.bericht.caretPos) {
        var caretPos = document.berichtenbalk.bericht.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
        document.berichtenbalk.bericht.focus();
    } else {
    document.berichtenbalk.bericht.value  += text;
    document.berichtenbalk.bericht.focus();
    }
}
</script>
<form action="post.php" method="post" name="berichtenbalk">
<table width="200" border="1" cellpadding="2" cellspacing="0" bordercolor="#999999" bgcolor="#CCCCCC">
  <tr>
    <td colspan="3" height="25" background="img/toptabel2.gif">Plaats een bericht</td>
  </tr>
  <tr>
    <td  colspan=2>Naam
    <input name="naam" type="text" maxlength="10" size=13></td></TR>
    <TR>
    <td width="50" >Bericht<br>
    <table width="100" border="0" cellspacing="0" cellpadding="5">
                <tr align="center">
                  <td colspan="4" class="gensmall"><b>Emoticons</b></td>
                </tr>
                <tr align="center" valign="middle">
                  <td><a href="javascript:emoticon(':D:')"><img src="./smily/Blij.gif" border="0" alt="Very Happy" title="Very Happy" /></a></td>
                  <td><a href="javascript:emoticon(':L:')"><img src="./smily/lach.gif" border="0" alt="Smile" title="Smile" /></a></td>
                  <td><a href="javascript:emoticon(':te:')"><img src="./smily/teleurgesteld.gif" border="0" alt="Sad" title="Sad" /></a></td>
                  <td><a href="javascript:emoticon(':O:')"><img src="./smily/o.gif" border="0" alt="Surprised" title="Surprised" /></a></td>
                </tr>
                <tr align="center" valign="middle">
                  <td><a href="javascript:emoticon(':OO:')"><img src="./smily/bril.gif" border="0" alt="Shocked" title="Shocked" /></a></td>
                  <td><a href="javascript:emoticon(':S:')"><img src="./smily/s.gif" border="0" alt="Confused" title="Confused" /></a></td>
                  <td><a href="javascript:emoticon(':8:')"><img src="./smily/cool.gif" border="0" alt="Cool" title="Cool" /></a></td>
                  <td><a href="javascript:emoticon(':ga:')"><img src="./smily/lol.gif" border="0" alt="Laughing" title="Laughing" /></a></td>
                </tr>
                <tr align="center" valign="middle">
                  <td><a href="javascript:emoticon(':BB:')"><img src="./smily/boos.gif" border="0" alt="Mad" title="Mad" /></a></td>
                  <td><a href="javascript:emoticon(':ha:')"><img src="./smily/grap.gif" border="0" alt="Razz" title="Razz" /></a></td>
                  <td><a href="javascript:emoticon(':ops:')"><img src="./smily/bloos.gif" border="0" alt="Embarassed" title="Embarassed" /></a></td>
                  <td><a href="javascript:emoticon(':H:')"><img src="./smily/huil.gif" border="0" alt="Crying or Very sad" title="Crying or Very sad" /></a></td>
                </tr>
                <tr align="center" valign="middle">
                  <td><a href="javascript:emoticon(':DD:')"><img src="./smily/duivel.gif" border="0" alt="Evil or Very Mad" title="Evil or Very Mad" /></a></td>
                  <td><a href="javascript:emoticon(':HM:')"><img src="./smily/denk.gif" border="0" alt="Rolling Eyes" title="Rolling Eyes" /></a></td>
                  <td><a href="javascript:emoticon(':kni:')"><img src="./smily/knipoog.gif" border="0" alt="Wink" title="Wink" /></a></td>
                  <td><a href="javascript:emoticon(':!:')"><img src="./smily/!.gif" border="0" alt="Exclamation" title="Exclamation" /></a></td>
                </tr>
                <tr align="center" valign="middle">
                  <td><a href="javascript:emoticon(':vr:')"><img src="./smily/vraag.gif" border="0" alt="Question" title="Question" /></a></td>
                  <td><a href="javascript:emoticon(':ide:')"><img src="./smily/lamp.gif" border="0" alt="Idea" title="Idea" /></a></td>
                  <td><a href="javascript:emoticon(':P:')"><img src="./smily/pijl.gif" border="0" alt="Arrow" title="Arrow" /></a></td>
                  <td><a href="javascript:emoticon(':N:')"><img src="./smily/neutraal.gif" border="0" alt="Neutral" title="Neutral" /></a></td>
                </tr>
                <tr align="center">
                  <td colspan="4"><span  class="nav"></span></td>
                </tr>
                <tr><td colspan="4"></td></tr>
              </table>
    
    </td><TD><input name="bericht" type="text" maxlength="75" size=20 ></TD></TR>
    <Tr><td width="83" colspan=2>
    <input type="submit" name="post" value="Post bericht"></td>
  </tr>
</table>
</form>

---------post.php-------------
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?
mysql_connect("localhost","usernaam","wachtwoord");  
// mysql_connect maakt verbinding - mysql_connect("host naam","usernaam","wachtwoord")  

 mysql_select_db("balk");  
$ip= $_SERVER['REMOTE_ADDR'] ;
$query = mysql_query("SELECT * FROM bericht WHERE ip = '".$ip."'"); // selecteer IP
if($row = mysql_fetch_array($query))
{

    $rowid= $row["id"];
    $rowip= $row["ip"];
    $rowaan= $row["aant"];
    if ( $rowaan == 2 ) //-- vul hier het Max aantal per IP
    {  // Max bereikt
        exit("U kunt niet meer dan 2 Berichten plaatsen");
    }

    else
    { $rowaan= $row["aant"];
    $rowaan ++ ;
    $query = mysql_query("UPDATE bericht SET aant = '".$rowaan."' WHERE ip = '".$ip."'");//UPDATE zo?
        // UPDATE database met aantal = 2 en accepteer bericht

    }
}

else
{    echo "INSERT";
$aant = "1";
$ip=$_SERVER['REMOTE_ADDR'] ;
mysql_query("INSERT INTO bericht  (id,ip,aant) VALUES ('','".$ip."','$aant')") or die(mysql_error($sql));
    // INSERT nieuwe met aantal =1 en accepteer bericht
}
?>


<?php
include ("config.php");

 
   mysql_query("INSERT INTO berichtenbalk (naam, bericht, ip) VALUES ('".$_POST['naam']."','".$_POST['bericht']."','".$ip."')") or die(mysql_error());

   echo "Je bericht is succesvol toegevoegd!<BR>";
   #mysql_query("UPDATE....//deze functie heb ik nog niet ontwikkeld omdat het schript niet goed werkt

?>

-----------config.php--------
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
$db_host
= "localhost"; // Naam van de host
$db_user = "gebruikersnaam"; //Je gebruikersnaam
$db_pass = "Je wachtwoord"; //Je wachtwoord
$db = "balk"; //Naam van de database

$teken = "- "; //teken tussen de berichten
$hoeveel = 20;  //het aantal berichten die in de balk mag verschijnen
$ip = $_SERVER['REMOTE_ADDR']; //ip opvragen

mysql_connect($db_host, $db_user, $db_pass); // je db connectie
mysql_select_db($db);
?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.