Public paste
raaaaaar!
By: raaaaaar! | Date: Jun 10 2010 12:20 | Format: PHP | Expires: never | Size: 15.02 KB | Hits: 3790

  1. //=============================================================================================
  2. // myPHPscripts Guestbook is Copyright ©2007, Scott J. LeCompte
  3. // Web Site: http://www.myphpscripts.net/scripts.php
  4. //
  5. // myPHPscripts Guestbook V1.3
  6. // By PhpScripts.net
  7. //
  8. // May be used free of charge. There is no copyright. Feel free to edit.
  9. // Need help with installation or customization? Visit:
  10. // http://www.myphpscripts.net
  11. //=============================================================================================
  12. //====================================== User Variables =======================================
  13. //=============================================================================================
  14.  
  15. // Admin login
  16. $admin = 'admin';
  17.  
  18. // Admin password
  19. $password = 'Karen123!';
  20.  
  21. // Path to your guestbook installation
  22. $script_path = '/HTML/guestbook/';
  23.  
  24. // URL to your homepage
  25. $home = ' http://www.rijopleidingdassen.nl/';
  26.  
  27. // Number of guestbook entries to display per page
  28. $limit = 10;
  29.  
  30. // Page background color
  31. $bg = '#CECECE';
  32.  
  33. // Page text color
  34. $text = '#000000';
  35.  
  36. // Link color
  37. $link = '#000000';
  38.  
  39. // Link hover color
  40. $hover = '#F00000';
  41.  
  42. // Table header background color
  43. $th_bg = '#000000';
  44.  
  45. // Table header text color
  46. $th_txt = '#FFFFFF';
  47.  
  48. // Top cell background color
  49. $bg1 = '#DBDBDB';
  50.  
  51. // Alternating cell background color #1
  52. $bg2 = '#FFFFFF';
  53.  
  54. // Alternating cell background color #2
  55. $bg3 = '#C0C0C0';
  56.  
  57. //=============================================================================================
  58. //====================================== Do Not Edit =========================================
  59. //=============================================================================================
  60.  
  61. ?>
  62. <style type="text/css">
  63. body {
  64.         background-color: <? echo $bg; ?>;;
  65.         color: <? echo $text; ?>;
  66.         background-image: url(/Pictures/backgroundblue.jpg);
  67. }
  68. a {
  69.         font-family: arial;
  70.         font-size: 12px;
  71.         font-weight: normal;
  72.         text-decoration: underline;
  73.         color: <? echo $link; ?>;
  74. }
  75. a:hover {
  76.         font-family: arial;
  77.         font-size: 12px;
  78.         font-weight: none;
  79.         text-decoration: underline;
  80.         color: <? echo $hover; ?>;
  81. }
  82. .tekst {
  83.         font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
  84. }
  85. .tekst {
  86.         font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
  87. }
  88. </style>
  89. <?
  90.  
  91. $file = '/var/www/g31529/rijopleidingdassen.nl/guestbook/entries/entries.txt';
  92. $entries = fopen($script_path . $file, 'r');
  93. $num_lines = count(file($script_path . $file));
  94.  
  95. if (isset($_REQUEST['show_admin'])) {
  96.         if (!isset($_SESSION['guestbook_admin'])) {
  97.                 $_SESSION['show_admin'] = true;
  98.                 echo '<meta http-equiv="refresh" content="0;url=' . $_SERVER['HTTP_REFERER'] . '">';
  99.         }
  100. }
  101. else if (isset($_REQUEST['logout'])) {
  102.         if (isset($_SESSION['guestbook_admin'])) {
  103.                 session_unset(guestbook_admin);
  104.                 echo '<meta http-equiv="refresh" content="0;url=' . $_SERVER['HTTP_REFERER'] . '">';
  105.         }
  106. }
  107. else if (isset($_REQUEST['admin_login'])) {
  108.         if (isset($_REQUEST['name']) && isset($_REQUEST['pass'])) {
  109.                 if ($_REQUEST['name'] == $admin && $_REQUEST['pass'] == $password) {
  110.                         $_SESSION['guestbook_admin'] = $admin;
  111.                         echo '<meta http-equiv="refresh" content="0;url=' . $_SERVER['HTTP_REFERER'] . '">';
  112.                 }
  113.                 else {
  114.                         session_unset(guestbook_admin);
  115.                         echo '<meta http-equiv="refresh" content="0;url=' . $_SERVER['HTTP_REFERER'] . '">';
  116.                 }
  117.         }
  118. }
  119.  
  120. else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
  121.         if (isset($_SESSION['guestbook_admin']) && isset($_REQUEST['entry'])) {
  122.                 $key = $_REQUEST['entry'];
  123.                 $fc=file($script_path . $file);
  124.                 $f=fopen($script_path . $file,"w");
  125.                 foreach($fc as $line) {
  126.                       if (!strstr($line,$key))
  127.                             fputs($f,$line);
  128.                 }
  129.                 fclose($f);
  130.         }
  131.         echo '<meta http-equiv="refresh" content="0;url=' . $_SERVER['HTTP_REFERER'] . '">';
  132.         exit();
  133. }
  134.  
  135. else if (isset($_REQUEST['add_msg']) && $_REQUEST['add_msg'] == NULL) {
  136.         $_SESSION['referrer'] = $_SERVER['HTTP_REFERER'];
  137.         ?>
  138. <script language="javascript" type="text/javascript">
  139.        
  140.         function rand(n) {
  141.           return (Math.floor(Math.random()*n+1));
  142.         }
  143.        
  144.         function newcode() {
  145.             var sec;
  146.             sec = document.getElementById("img");
  147.             if (sec)
  148.                 sec.setAttribute("src",sec.src+rand(9));
  149.         }
  150.         // -->
  151.         </script>
  152.         <title>Rijopleiding Dassen: Gastenboek</title><div>
  153.                 <center>
  154.                         <table style="border:1px solid #000000; border-collapse:collapse; background-color:<? echo $bg1; ?>;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size:12px;">
  155.                                 <tr>
  156.                                         <th style="background-color:<? echo $th_bg; ?>;color:<? echo $th_txt; ?>;">New Message</th>
  157.                                 </tr>
  158.                                 <tr>
  159.                                         <td style="text-align:left;padding:0px 10px 0px 10px;">
  160.                                                 <form action="<? echo $_PHP['SELF']; ?>" method="post">
  161.                                                         <p>
  162.                                                           <? $userip = $_SERVER['REMOTE_ADDR']; echo '<input type="hidden" name="ip" value="' . $userip . '">'; ?>
  163.                                                           <br>
  164.                                                         <? $date = date('M j, Y'); echo '<input type="hidden" name="date" value="' . $date . '">'; ?><br>
  165.                        
  166.                                                         <span class="tekst">Name:</span><br>
  167.                                                         <input type="text" name="name" size="40"><br>  
  168.                                                                                                                                        
  169.                                                        
  170.                                                         Message:<br>
  171.                                                     <textarea name="comment" rows="10" cols="40"></textarea>
  172.                                                     <br>
  173.                        
  174.                                                         Security Code:<br>
  175.                                                         <img src="txt2png.php?" name="img" id="img" alt="Security Code" title="Security Code"></p>
  176.                                                         <p><br>
  177.                        
  178.                                                         Type the Code:<br>
  179.                                                         <input id="security_code" name="security_code" type="text">
  180.                                                         <input type="submit" name="add_msg" value="Send">
  181.                                                         <input type="reset" value="Clear">
  182.                                                         </p>
  183.                         </form>
  184.                                         </td>
  185.                                 </tr>
  186.                                 <tr>
  187.                                         <td align="center">
  188.                                                 <br><a href="" onclick="newcode(); return false;">Click Here</a> for a new code.<br><br>
  189.                                         </td>
  190.                                 </tr>
  191.                         </table>
  192.                 </center>
  193.         </div> 
  194.         <?
  195.         echo '</body>';
  196.         echo '</html>';
  197.         exit();
  198. }
  199.  
  200. else if (isset($_REQUEST['add_msg']) && ($_REQUEST['add_msg'] == 'Send' || $_REQUEST['add_msg'] == 'new')) {
  201.         $id = time();
  202.         $date = stripslashes($_REQUEST['date']);
  203.         $name = stripslashes(str_replace(array("n","<",">"), array(" ","&lt;","&gt"), $_REQUEST['name']));
  204.         $ip = stripslashes($_REQUEST['ip']);
  205.         $comment = stripslashes(str_replace(array("<",">","n"), array("&lt;","&gt","<br>"), $_REQUEST['comment']));
  206.         if ($_REQUEST['add_msg'] == 'new') {
  207.                 $error = '';
  208.         }
  209.         else if (!isset($_REQUEST['security_code']) || !isset($_SESSION['security_code']) || $_REQUEST['security_code'] != $_SESSION['security_code']) {
  210.                 $error = '<b><font color="#F000000">Error: </font></b>Wrong security code!';
  211.         }
  212.         else if (!isset($_REQUEST['name']) || $name == '') {
  213.                 $error = '<b><font color="#F000000">Error: </font>M</b>Name not entered.';
  214.         }
  215.         else if (!isset($_REQUEST['date']) || $date == '') {
  216.                 $error = '<b><font color="#F000000">Error: </font></b>Date not set.';
  217.         }
  218.         else if (!isset($_REQUEST['ip']) || $ip == '') {
  219.                 $error = '<b><font color="#F000000">Error: </font></b>IP not set.';
  220.         }
  221.         else if (!isset($_REQUEST['comment']) || $comment == '') {
  222.                 $error = '<b><font color="#F000000">Error: </font></b>No Comment entered.';
  223.         }
  224.         else {
  225.                 $error = '<b><font color="#0000000">Success: </font></b>Your message has been posted.';
  226.                 $new_line = "$id|$date|$name|$ip|$commentn";
  227.                 $old_lines = file($script_path . $file);
  228.                 array_unshift($old_lines,$new_line);
  229.                 $new_content = join('',$old_lines);
  230.                 $fp = fopen($script_path . $file,'w');
  231.                 $write = fwrite($fp, $new_content);
  232.                 fclose($fp);
  233.                 echo '<meta http-equiv="refresh" content="2;url=' . $_SESSION['referrer'] . '">';
  234.         }
  235. }
  236. ?>
  237.  
  238. <div>
  239.         <center>
  240.                 <table style="width:600px;padding:0px;border-collapse:collapse;font-size:12px;font-family:arial;">
  241.                         <tr>
  242.                                 <td style="padding:0px 0px 10px 10px;text-align:left;width:200px;">
  243.                                 <?
  244.                                         $pages = ceil($num_lines / $limit);
  245.                                         if ($_GET['pg'] >= 1 && $pages != 0) {
  246.                                                 if ($_GET['pg'] == 1) {
  247.                                                         echo '[ ';
  248.                                                 }
  249.                                                 else {
  250.                                                         echo '[ <a href="' . $_PHP['SELF'] . '?pg=' . ($_GET['pg'] - 1) . '">...</a> | ';
  251.                                                 }
  252.                                         }
  253.                                         $p = 1;
  254.                                         while ($p <= $pages) {
  255.                                                 if (isset($_GET['pg'] )) {
  256.                                                         if ($_GET['pg'] == $p ) {
  257.                                                                 if ($p == $pages) {
  258.                                                                         echo '<b>' . $p . '</b>';
  259.                                                                 }
  260.                                                                 else {
  261.                                                                         echo '<b>' . $p . '</b> | ';
  262.                                                                 }
  263.                                                         }
  264.                                                         else if ($_GET['pg'] <= 2) {
  265.                                                                 if ($p <= 5) {
  266.                                                                         if ($p < 5) {
  267.                                                                                 if ($pages <= 5 && $_GET['pg'] >= 1) {
  268.                                                                                         if ($p == $pages) {
  269.                                                                                                 echo '<a href="' . $_PHP['SELF'] . '?pg=' . $p . '">' . $p . '</a>';
  270.                                                                                         }
  271.                                                                                         else {
  272.                                                                                                 echo '<a href="' . $_PHP['SELF'] . '?pg=' . $p . '">' . $p . '</a> | ';
  273.                                                                                         }
  274.                                                                                 }
  275.                                                                                 else if ($pages > 5 && $_GET['pg'] >= 1) {
  276.                                                                                         echo '<a href="' . $_PHP['SELF'] . '?pg=' . $p . '">' . $p . '</a> | ';
  277.                                                                                 }
  278.                                                                         }
  279.                                                                         else {
  280.                                                                                 echo '<a href="' . $_PHP['SELF'] . '?pg=' . $p . '">' . $p . '</a>';
  281.                                                                         }
  282.                                                                 }                                                      
  283.                                                         }
  284.                                                         else if ($_GET['pg'] == $pages) {
  285.                                                                 if ($p >= $_GET['pg'] - 4) {
  286.                                                                         echo '<a href="' . $_PHP['SELF'] . '?pg=' . $p . '">' . $p . '</a> | ';
  287.                                                                 }                                                              
  288.                                                         }
  289.                                                         else if ($_GET['pg'] + 1 == $pages) {
  290.                                                                 if ($p == $_GET['pg'] + 1) {
  291.                                                                         echo '<a href="' . $_PHP['SELF'] . '?pg=' . $p . '">' . $p . '</a>';
  292.                                                                 }
  293.                                                                 else if ($p >= $_GET['pg'] - 3 && $p <= $_GET['pg'] + 3) {
  294.                                                                         echo '<a href="' . $_PHP['SELF'] . '?pg=' . $p . '">' . $p . '</a> | ';
  295.                                                                 }
  296.                                                         }
  297.                                                         else if (($p <= $_GET['pg'] + 2) && ($p >= $_GET['pg'] - 2)) {
  298.                                                                 if ($p == $pages) {
  299.                                                                         echo '<a href="' . $_PHP['SELF'] . '?pg=' . $p . '">' . $p . '</a>';
  300.                                                                 }
  301.                                                                 else if ($p == $_GET['pg'] + 2) {
  302.                                                                         echo '<a href="' . $_PHP['SELF'] . '?pg=' . $p . '">' . $p . '</a>';
  303.                                                                 }
  304.                                                                 else {
  305.                                                                         echo '<a href="' . $_PHP['SELF'] . '?pg=' . $p . '">' . $p . '</a> | ';
  306.                                                                
  307.                                                                 }
  308.                                                         }
  309.                                                 }
  310.                                                 else {
  311.                                                         if ($p <= 5) {
  312.                                                                 if ($p == 1 && $pages > 1) {
  313.                                                                         echo '[ <b>' . $p . '</b> | ';
  314.                                                                 }
  315.                                                                 else if ($p == 1 && $pages == 1) {
  316.                                                                         echo '[ <b>' . $p . '</b>';
  317.                                                                 }
  318.                                                                 else if ($p < 5 && $pages > 1) {
  319.                                                                         if ($p == $pages) {
  320.                                                                                 echo '<a href="' . $_PHP['SELF'] . '?pg=' . $p . '">' . $p . '</a>';
  321.                                                                         }
  322.                                                                         else {
  323.                                                                                 echo '<a href="' . $_PHP['SELF'] . '?pg=' . $p . '">' . $p . '</a> | ';
  324.                                                                         }
  325.                                                                 }
  326.                                                                 else {
  327.                                                                         echo '<a href="' . $_PHP['SELF'] . '?pg=' . $p . '">' . $p . '</a>';
  328.                                                                 }
  329.                                                         }
  330.                                                 }
  331.                                                 $p++;
  332.                                         }
  333.                                         if (($_GET['pg'] <= $pages || !isset($_GET['pg'])) && $pages != 0) {
  334.                                                 if ($pages < 2) {
  335.                                                         echo ' ]';
  336.                                                 }
  337.                                                 else if (!isset($_GET['pg'])) {
  338.                                                         echo ' | <a href="' . $_PHP['SELF'] . '?pg=2">...</a> ]';
  339.                                                 }
  340.                                                 else if ($_GET['pg'] == $pages) {
  341.                                                         echo ' ]';
  342.                                                 }
  343.                                                 else {
  344.                                                         echo ' | <a href="' . $_PHP['SELF'] . '?pg=' . ($_GET['pg'] + 1) . '">...</a> ]';
  345.                                                 }
  346.                                         }
  347.                                 ?>
  348.                                 </td>
  349.                                 <td style="padding:0px 0px 10px 0px;text-align:center;width:250px;"><? echo $error; ?></td>
  350.                                 <td style="padding:0px 10px 10px 10px;text-align:right;width:300px;">[ <a href="<? echo $home; ?>">Back to Homepage</a> ] [ <a href="<? echo $_PHP['SELF']; ?>?add_msg">Add a message</a> ]</td>
  351.                         </tr>
  352.                 </table>
  353.         </center>
  354. </div>
  355. <div>
  356.         <center>
  357.                 <table style="border:1px solid black;width:600px;padding:0px;border-collapse:collapse;font-size:12px;font-family:arial;">
  358.                         <tr>
  359.                                 <th width="171" style="background:#000000; color:#FFFFFF; height:20px; font-family: 'Trebuchet MS', Arial, Helvetica, sans-serif;">Poster</th>
  360.                                 <th width="417" style="background-color:<? echo $th_bg; ?>;color:<? echo $th_txt; ?>; height:20px; font-family: 'Trebuchet MS', Arial, Helvetica, sans-serif;">Message</th>
  361.                         </tr>
  362.                                
  363.                                 <?
  364.                                         if(isset($_GET['pg'])){  
  365.                                                 $start = $limit * ($_GET['pg'] - 1);
  366.                                         }
  367.                                         else {  
  368.                                                 $start = 0;  
  369.                                         }
  370.                                         if ($entries) {
  371.                                                 $i = 0;
  372.                                                 $j = 0;
  373.                                                 while (!feof($entries)) {
  374.                                                         if ($bg == $bg1) { $bg = $bg2; }
  375.                                                         else { $bg = $bg1; }
  376.                                                         $line[] = fgets($entries, 4096);
  377.                                                         $array = explode('|', $line[$i]);
  378.                                                         if ($i < $num_lines && $i >= $start && $j < $limit) {
  379.                                                         ?>
  380.                         <tr style="background-color:<? echo $bg; ?>;">
  381.                                                                 <td style="background-color:<? echo $bg3; ?>;height:20px;border-top:1px solid #000000;border-bottom:1px solid #000000;padding:0px 10px 0px 10px;text-align:left;vertical-align:middle">
  382.                                                                         <? echo '<b>Posted on</b> ' . $array[1]; ?>
  383.                                                                 </td>
  384.                                                                 <td style="background-color:<? echo $bg3; ?>;height:20px;border-top:1px solid #000000;border-bottom:1px solid #000000;padding:0px 10px 0px 10px;text-align:right;vertical-align:middle">
  385.                                                                         <? if (isset($_SESSION['guestbook_admin'])) { echo '<b>IP:</b> ' . $array[5] . ' | '; } ?>
  386.                                                                         <? if (isset($_SESSION['guestbook_admin'])) { echo '<a href="' . $_PHP['SELF'] . '?action=delete&amp;entry=' . $array[0] . '" onclick="return confirm('Are you sure you want to delete this message?')">Delete</a>'; } ?>
  387.                                                                 </td>
  388.                         </tr>
  389.                         <tr style="background-color:<? echo $bg; ?>;">
  390.                                                                 <td style="border-right:1px solid #000000;width:150px;padding:10px;text-align:left;vertical-align:top">
  391.                                                                 <? echo '<b>Name:</b> ' . $array[2] . '<br>'; ?></td>
  392.                                                                 <td style="padding:10px;text-align:left;vertical-align:top">
  393.                                                                         <? echo $array[6] . '<br>'; ?>
  394.                                                                 </td>
  395.                         </tr>                                                  
  396.                                                         <?
  397.                                                                 $j++;
  398.                                                         }
  399.                                                         $i++;
  400.                                                 }
  401.                                         fclose($entries);
  402.                                         }
  403.                                 ?>
  404.                 </table>
  405.                 <table style="width:600px;padding:0px;border-collapse:collapse;font-size:12px;font-family:arial;text-align:right;">
  406.                         <tr>
  407.                                 <td style="text-align:right;padding:10px 10px 0px 0px;">
  408.                                         <?
  409.                                         if (!isset($_SESSION['show_admin']) && !isset($_SESSION['guestbook_admin'])) {
  410.                                         ?>
  411.                                         [ <a href="<? echo $_PHP['SELF'] . '?show_admin' ?>">Admin</a> ]
  412.                                         <?
  413.                                         }
  414.                                         else if (!isset($_SESSION['guestbook_admin']) && isset($_SESSION['show_admin'])) {
  415.                                         ?>
  416.                                         <table style="width:100%;">
  417.                                                 <tr>
  418.                                                         <td style="font-family:arial;font-size:12px;height:12px;text-align:right">
  419.                                                                 <form action="<? echo $_PHP['SELF']; ?>" method="post">
  420.                                                                         Name:
  421.                                                                   <input type="text" name="name" size="15"><br>
  422.                                                                         <span class="tekst">Pass</span>:
  423. <input type="password" name="pass" size="15"><br>
  424.                                                                         <input type="submit" name="admin_login" value="Login">
  425.                                                                 </form>
  426.                                                         </td>
  427.                                                 </tr>
  428.                                         </table>
  429.                                         <?
  430.                                         }
  431.                                         else {
  432.                                         ?>
  433.                                         <table style="width:100%;">
  434.                                                 <tr>
  435.                                                         <td style="font-family:arial;font-size:12px;height:12px;text-align:right">
  436.                                                                 Logged in as <? echo $_SESSION['guestbook_admin'] . ' - [ <a href="' . $_PHP['SELF'] . '?logout">Logout</a> ]'; ?>
  437.                                                   </td>
  438.                                           </tr>
  439.                                         </table>
  440.                                         <? } ?>
  441.                                 </td>
  442.                         </tr>
  443.                         <tr>
  444.                                 <td style="text-align:center;font-family:arial;font-size:12px;color:<?php echo $text; ?>">&nbsp;</td>
  445.                         </tr>
  446.                 </table>
  447.         </center>
  448. </div>