thaiall logomy background
coding : webboardphp.txt.
my town
Source : Perl | PHP | ASP | JSP | HTML | HTML5 | JavaScript | Java | COBOL | C++ | MS Access | VBNet | VB | Python | โค้ดดี
File : webboardphp.txt. ID : 9119
Skin : Default | Sons-of-obsidian | Sunburst | Highlighter | Full
<?php

// session_save_path("/tmp");

session_start();

/*

### webboard.php Version : 2.0

Public : Mr.Burin Rujjanapan 

E-mail : webmaster@thaiall.com 

Last Modified : 2557-02-08 Created : 2547-12-01 

Download : http://www.thaiall.com/source 



### รายละเอียด (Detail)

1. โปรแกรมนี้ชื่ออะไรก็ได้ เช่น webboard.php board.php doc.php news.php แต่ให้นามสกุลเป็น .php 

2. ให้ผู้ดูแลระบบเปลี่ยนรหัสผ่าน เป็นอย่างอื่นทันที 

 ของ $webmaster_password เดิมคือ thaiabc 

 ของ $edit_topic_password เดิมคือ thaiall 

 เพราะนักเรียนอาจเข้ามาใช้รหัสผ่าน ลบหัวข้อ หรือแก้ไขหัวข้อได้ 

3. กำหนด $program_type และ $dataroom ตามที่ต้องการ 

4. โปรแกรมประกอบด้วย 3 ส่วน คือ 1)Setting 2)Main และ 3)Function

5. ทดสอบกับ xampp แล้วใช้งานได้ทันทีไม่ต้องปรับแต่งเลย

แต่ต้องแก้ไข DOCUMENTROOT และ <DIRECTORY "..">



### ปัญหา และวิธีแก้ไข (Problem and Solution)

กรณีที่ 1 (About installation) 

- เปิด webboard.php ครั้งแรก คือ การติดตั้ง 

- ปัญหาที่อาจเกิด คือ Permission Denied ในการสร้าง Folder สำหรับ Linux 

- ท่านต้องกำหนด 777 ให้กับห้องที่เก็บโปรแกรมนี้ 

- ท่านต้องสร้างห้อง wdata ในห้องที่เก็บโปรแกรม และกำหนดเป็น 777 

กรณีที่ 2 (Just information) 

- แค่ run โปรแกรมก็จะติดตั้งให้ และใช้งานได้ทันที (ทดสอบกับ XP Server) 

- ไม่พบปัญหา แต่ท่านต้องเปิดโปรแกรมมาแก้ไขค่าตามต้องการ เช่น รหัสลบหัวข้อ 

*/

#########################################################################

### 1) Setting Section

### Setting Group 1 : ค่าสำคัญที่ผู้ดูแลต้องเข้าใจ

$webmaster_password = "thaiabc";  // รหัสนี้ใช้ลบหัวข้อ

$edit_topic_password = "thaiall"; // รหัสนี้ใช้แก้ไขหัวข้อ

$program_type = "board";      

  // board     อ่านได้เขียนได้

  // news      ไม่แสดง link ให้ตั้งหัวข้อกันเอง

  // intranet  ความคุมการเข้าถึงด้วย IP address

  // password  ต้องกรอก $read_password จึงจะอ่านได้ (คุมการเขียนด้วยตัวแปร $add_keyword และ $add_text)

  // intrapass เป็นทั้ง intranet และมีระบบ password (ถือเป็น secure board)

  // puser     ต้องเป็นสมาชิกจึงจะ post ได้ สามารถสร้าง user ในตัวแปร $user อยู่ใน Group 4

  // ถ้าไม่อยากให้ตอบ ต้องแก้ตัวแปร $can_reply ให้เป็น "0" ถ้าใช้ร่วมกับ news จะเป็น readonly

if ($program_type == "board")     $bgcolor="ddffff"; 

if ($program_type == "news")      $bgcolor="ddffdd";

if ($program_type == "intranet")  $bgcolor="ffddff";

if ($program_type == "password")  $bgcolor="ddddff";

if ($program_type == "intrapass") $bgcolor="ffdddd";

if ($program_type == "puser")      $bgcolor="ffffdd";

if (!isset($bgcolor)) $bgcolor="ddffdd";



### Setting Group 2 : ค่าทั่วไป

$dataroom      = "wdata";     // ห้องเก็บข้อมูล

$max_file_size = 2097152;     // 2 MB

$max_note      = 204800;      // 200 KB

$max_text      = 1024;        // size of text (title + name + email)

$titleperpage  = 10;          // จำนวนหัวข้อต่อหน้า

$allow_extension = "html,gif,jpg,png,txt,dbf,dat,class,swf,rar,zip,ppt,doc,xls,mdb,pdf";

#

$title         = "กระดานแสดงความคิดเห็น";

$footer        = "พัฒนาเพิ่มเติมโดย : thaiall.com [ ไอพีของท่านคือ ". $_SERVER["REMOTE_ADDR"] . " ]";

$footer       .= "<br>ปรับปรุง : 8 กุมภาพันธ์ 2557 รุ่น : 2.0";

$header        = "<center><font size=6>$title</font><br>";

$header_reply = '<b>ขอเชิญร่วมแสดงความคิดเห็น<br>(Welcome your good idea)</b>';

$header_add_topic = 'Web board เป็นที่แลกเปลี่ยนความคิดเห็นของพวกเราทุกคน<br>ขอความกรุณาใช้ถ้อยคำสุภาพ และแสดงออกในเชิงสร้างสรรค์ ที่มีเหตุผลด้วย<br><font color=red>ขอสงวนสิทธิ์ ในการแก้ไข ตัดรายการ หรือข้อความ <b>ที่ไม่เหมาะสม</b> โดยผู้ดูแลระบบ</font>';

$option_text = "<font color=blue>[dd] หรือ [b] .. [/b] หรือ [u] .. [/u]<br>[img]<font color=black>http://..../x.jpg</font>[/img]<br>[url]<font color=black>http://..../x.htm</font>[/url]</font>";

#

$file_header   = "";    // ถ้ากำหนดชื่อแฟ้ม เช่น h.php จะอ่านข้อมูลในแฟ้มมาเป็น header

$file_footer   = "";    // ถ้ากำหนดชื่อแฟ้ม เช่น f.php จะอ่านข้อมูลในแฟ้มมาเป็น footer

// for add-on สำหรับนำไป add-on ในโปรแกรมอื่น

$show_header   = "yes"; // no = ไม่แสดง 

$show_footer   = "yes"; // no = ไม่แสดง

$show_writer   = "yes"; // no = ไม่แสดง

$show_counter  = "yes"; // no = ไม่แสดง

$can_reply     = "yes"; // no = ไม่รับการตอบหัวข้อ  yes:ยอมให้มีการตอบหัวข้อ

//

$have_header   = "yes"; // writer header of html

$show_header_tb= "yes"; // no = ไม่แสดง

$show_no       = "yes"; // no = ไม่แสดง

$can_search    = "yes"; // no = ไม่แสดง



$icon_file     = "iticon.gif"; // ถ้ามีแฟ้มชื่อนี้ ก็จะแสดง icon หน้าหัวข้อ

$table_width   = "700"; // 700



### Setting Group 3 : สำหรับการป้องกันการเพิ่มหัวข้อ และทำงานร่วมกันถ้า $program_type = "news"

$add_keyword   = "add_topic";   // การเปลี่ยนค่านี้จะทำให้ผู้ใช้เพิ่มหัวข้อไม่ได้ ถ้าไม่ทำ link ไว้

$add_text      = "<center><a href='?action=".$add_keyword."'>ตั้งหัวข้อ หรือเปิดประเด็นใหม่</a></center>";



### Setting Group 4 : เก็บอาร์เรย์ของตัวแปรต่าง ๆ

# ถ้า $program_type = "intranet" จะตรวจสอบ ip ของเครื่องลูก ถ้าไม่มีใน array จะเข้า board ไม่ได้

$intranet = array("192.168.0", "202.29.78", "10.0.0", "127.0.0");

# ถ้า $program_type = "password" จะตรวจสอบ รหัสผ่านก่อนเข้า board มีให้หลายรหัส เพราะอาจมีผู้ใช้หลายกลุ่ม

$password_ar = array("thaiabc", "yoyo", "pizza");

# ถ้าไม่กำหนด $program_type = "puser" ตัวแปร $user ก็จะไม่ได้ใช้ประโยชน์

# $user["username"] = "password"

$user["boy"]      = "girl";

$user["thaiall"]  = "thaiabc";

$user["จักรพงษ์"] = "ศุขวิทย์"; // อ.ท่านนี้ให้หลวงพ่อเงิน และทำให้ผมเพิ่ม option นี้

$user["เอ บี"]    = "ซี ดี";    // ทดสอบรหัสที่มีช่องไฟ



#########################################################################

### 2) Main Script Section

if ($program_type == "puser") {

  if (isset($_POST["puser"]) && isset($user[$_POST["puser"]]) && $user[$_POST["puser"]] == $_POST["ppassword"]) {

    $_SESSION['puser'] = $_POST["puser"];

  }

  if (isset($_POST["logout"])) {

    $_SESSION['puser'] = "";

  }

}

if ($program_type == "password" || $program_type == "intrapass") {

  if (!isset($_SESSION['password'])) {

    if (isset($_POST['password'])) {

      if (in_array($_POST['password'], $password_ar)) { 

        $_SESSION['password'] = $_POST['password'];

      } else {

        echo '<meta http-equiv=refresh content="5;url=?pg=1">';

        echo 'รหัสผ่านไม่ถูกต้อง';

      }

    } else {

      text_header();

      echo "<br><br><form action=? method=post>";

      echo "<center>Password to access information<br>";

      echo "<input name=password type=password>";

      echo "<input type=submit value=check name=action></form>";

      text_footer();

    }

  }

}

if ($program_type == "intranet" || $program_type == "intrapass") {

  $found_ar = 0;

  for($i=0;$i<count($intranet);$i++) {

    if (substr($_SERVER["REMOTE_ADDR"],0,strlen($intranet[$i]))  == $intranet[$i]) $found_ar=1;

  } 

  if ($found_ar != 1) {

    text_header();

    echo "<center>IP address ของท่าน ไม่สามารถเข้าใช้โปรแกรมนี้<br>โปรดติดต่อผู้ดูแลระบบ<br>";

    echo "เพราะกลุ่ม ip ที่อนุญาต คือ";

    for($i=0;$i<count($intranet);$i++) echo "<br>".$intranet[$i];

    text_footer();

  } 

}

# ===============================

if (isset($_GET['reply']))   $reply   = $_GET['reply'];   else $reply   = "";

if (isset($_GET['d']))       $delete  = $_GET['d'];       else $delete  = "";

if (isset($_GET['e']))       $edit    = $_GET['e'];       else $edit    = "";

if (isset($_GET['view']))    $view    = $_GET['view'];    else $view    = "";

if (isset($_GET['secure']))  $secure  = $_GET['secure'];  else $secure  = "";

if (isset($_GET['action']))  $actiong = $_GET['action'];  else $actiong = "";

if (isset($_POST['action'])) $actionp = $_POST['action']; else $actionp = "";

# ===============================

if (!file_exists($dataroom."/topic.htm"))     startup_firsttime();

elseif ((!isset($_SERVER['QUERY_STRING']) && !isset($_POST['action'])) || isset($_GET['pg']) || isset($_GET['tot'])) list_main(); 

elseif ($reply <> "")              reply_topic();

elseif ($view <> "")               view_topic();

elseif ($secure <> "")             secure_code_r();

elseif ($delete <> "")             delete_topic();

elseif ($edit <> "")               edit_topic();

elseif ($actiong == "secure_code") secure_code();

elseif ($actiong == $add_keyword)  add_topic();

elseif ($actionp == "send_topic")  send_topic();

else list_main(); //  echo '<meta http-equiv=refresh content="5;url=?pg=1">';

#########################################################################

### 3) Function Section

function send_topic() {

text_header();

global $allow_extension,$max_file_size,$max_note,$max_text,$dataroom,$last_ext,$program_type,$add_keyword,$table_width;

# -------

$found_attach_ok = 0;

$ar_last_ext = explode(".",$_FILES['upload']['name']);  

if (count($ar_last_ext) > 1) {

    $last_ext = $ar_last_ext[count($ar_last_ext) - 1];

    $ar = explode(",",$allow_extension);

    $found_ext = 0;

    for ($i=0;$i<count($ar);$i++){

      if (strtolower($last_ext) == strtolower($ar[$i])) { $found_ext = 1; }

    }    

    if ($found_ext == 1) {

      $size = $_FILES['upload']['size'];

      // == upload process ==  

      if ($size > 0 && $size < $max_file_size) {

        $found_attach_ok = 1;

      } else {

        $found_attach_ok = 9;

        echo "<center><table width=". $table_width ." bgcolor=yellow align=center><td><center>ส่งแฟ้มเข้า server ไม่ได้ ขนาดแฟ้มอาจเกิดที่กำหนด  (<font color=blue>$"."max_file_size = ".$max_file_size.")</font><br>";

        echo "แฟ้มของคุณมีขนาด <b>$size</b> Byte และ <font color=red>มีขนาดไม่เหมาะกับระบบของเรา</td></table>";

      }

    } else {

      $found_attach_ok = 9;

      echo "<center><table width=". $table_width ." bgcolor=yellow align=center><td><center>ไม่อนุญาตแฟ้มที่มีนามสกุล <font size=6>$last_ext</font> อันมีเหตุผลมาจากความปลอดภัย<br>";

      echo "<font color=red>ถ้าท่านเห็นว่าแฟ้มขอท่านไม่น่ามีปัญหาเรื่องความปลอดภัย <b>โปรดติดต่อ webmaster</b> เพื่อรับการอนุญาต</td></table>";

    }

}

# -------

$textlen = strlen($_POST['qtitle']) + strlen($_POST['qname']) + strlen($_POST['qemail']);

if (($_POST['qtitle'] == "") || ($_POST['qnote'] == "") || ($_POST['qname'] == "") || 

  $found_attach_ok == 9 || strlen($_POST['qnote']) > $max_note || $textlen > $max_text) {

  echo "<b> พบข้อผิดพลาด </b> : คุณป้อนข้อมูลไม่ครบถ้วน หรือแฟ้มมีขนาดใหญ่เกินไป หรือนามสกุลของแฟ้มไม่ถูกต้อง<br>";

  echo '<meta http-equiv=refresh content="5;url=?pg=1">';

} else {

  $file=file ($dataroom."/topic.htm");

  $k=count($file);

  $key=ord(substr(crypt($k,$k),-1,1)) . ord(substr(crypt($k,$k),-2,1)); 

  if ($key == $_POST['securecode']) {

    $qtitle= $_POST['qtitle'];

    $qtitle = str_replace("?","&#63",$qtitle);

    $qnote= $_POST['qnote']; 

    $qnote = str_replace("?","&#63",$qnote);

    $qnote= str_replace(chr(92),"#92;",$qnote);

    $qnote= str_replace("[dd]","<dd>",$qnote); 

    $qnote= str_replace("[u]","<u>",$qnote); 

    $qnote= str_replace("[/u]","</u>",$qnote); 

    $qnote= str_replace("[b]","<b>",$qnote); 

    $qnote= str_replace("[/b]","</b>",$qnote); 

    $qnote= str_replace("[img]","<img src=",$qnote); 

    $qnote= str_replace("[/img]",">",$qnote); 

    $qnote= str_replace("[url]","[ <a href=",$qnote); 

    $qnote= str_replace("[/url]",">คลิ๊กที่นี่ - เพื่อเปิดแหล่งข้อมูล</a> ]",$qnote); 

    $qnote= str_replace("#92;","&#92;",$qnote);

    $qname= $_POST['qname'];

    $qname = str_replace("?","&#63",$qname);

    $qemail= $_POST['qemail'];

    $qemail = str_replace("?","&#63",$qemail);

    $qnote= nl2br($qnote);

    $qtitle= stripslashes($qtitle);

    $qnote= stripslashes($qnote);

    $qname= stripslashes($qname);

    $qemail= stripslashes($qemail);

    $file=fopen($dataroom."/number.txt","rt");

    $num=fgets($file,10);

    fclose ($file);

    $num++;

    $file=fopen($dataroom."/number.txt","w");

    fputs($file,$num);

    fclose($file);

    $date=Date("h:ia (j/m/y)");

    $attach_file = $num .".". strtolower($last_ext);

    $file=fopen("$dataroom/$num.htm" , "w");

    fputs ($file , "<center><a href='?'>กลับหน้าหลัก</a>");

    fputs ($file , "<table width=". $table_width ." border=0 bgcolor=#aabbdd><tr><td><font color=white size=4>$qtitle</td></tr></table>");

    fputs ($file , "<table width=". $table_width ." border=0 bgcolor=#aabbdd><tr><td bgcolor=white>");

    if ($found_attach_ok == 1) { 

      fputs ($file , "ดาวน์โหลด : <a href=$dataroom/$attach_file>$attach_file</a><br>");

      if (strtolower($last_ext) == "jpg" || strtolower($last_ext) == "gif" || strtolower($last_ext) == "png") { fputs ($file , "<img src=$dataroom/$attach_file><br>"); }

    }

    fputs($file , "$qnote<br></td></tr>");

    fputs($file , "<tr><td align=right bgcolor=#dddddd><b>โดย</b> : $qname <a href=mailto:$qemail>$qemail</a><a title='". $_SERVER["REMOTE_ADDR"] . "'>.</a> ");

    fputs($file , " $date</font></td></tr></table></center>");

    fclose($file);       

    $file=fopen("$dataroom/$num.reply" , "w");

    fputs($file , "0");

    fclose($file);

    $file=fopen($dataroom."/topic.htm" , "a");

    fputs ( $file , "<a href='?view=$num'>$qtitle</a>");

    if ($found_attach_ok == 1) fputs ($file , " [<a href=$dataroom/$attach_file>+</a>]");

    fputs ( $file , "</td><td align=center>$qname<br><font color=#669999>$date </font></td>\n");

    fclose ($file);   

    if ($found_attach_ok == 1) copy($_FILES['upload']['tmp_name'],"$dataroom/$num.". strtolower($last_ext));

    echo "<center><table bordercolor=black border=1 cellspacing =0 width=90% bgcolor=#ddffff><tr><td>";

    echo "<b>$qtitle</b><br>";

    if ($found_attach_ok == 1) echo "ดาวน์โหลด : <a href=$dataroom/$attach_file>$attach_file</a><br>";

    if (strtolower($last_ext) == "jpg" || strtolower($last_ext) == "gif" || strtolower($last_ext) == "png") { echo "<img src=$dataroom/$attach_file><br>"; }

    echo "<hr color=black>$qnote</td></tr>";

    echo "<tr><td align=right bgcolor=#dddddd><b>โดย</b> : $qname <a href=mailto:$qemail>$qemail</a><a title='". $_SERVER["REMOTE_ADDR"] . "'>.</a><br>";

    echo " $date</font></td></tr></table><br><a href='?'>กลับหน้าหลัก</a> เพื่อดูผลการเพิ่มหัวข้อใหม่</center>";

  } else {

    echo "<center><font size=4>ไม่พบรหัสลับที่ท่าน ควรป้อนเข้ามาอย่างถูกต้อง<br>ซึ่งแสดงเป็น อักษรขาวบนพื้นสีแดง หรือรหัสลับนั้นหมดอายุ<br>รบกวนช่วยกรอกข้อมูลใหม่ด้วยค่ะ และขออภัยในความไม่สะดวก<br><br><a href='javascript:history.back();' target=_top>กลับไปกรอกข้อมูลใหม่</a>";  

    if ($program_type <> "news") echo "<form action=? method=get><input type=submit name=action value='".$add_keyword."'></form>";

  }

}

}

# ===============================

function add_topic() {

text_header();

global $allow_extension,$program_type,$table_width,$option_text,$header_add_topic;

echo '<center><table width=' . $table_width . '><tr><td align=center>'. $header_add_topic . '</td>

<tr><form enctype="multipart/form-data" action="?" method=post target=_self><td align=center bgcolor=#ffffdd>

<table border=0 cellspacing=0  bgcolor=#dddddd width='. $table_width .'>

<tr><td>หัวข้อ (Subject) </td><td><input name=qtitle size=60 value=""></td></tr>

<tr><td valign=top>รายละเอียด</td><td valign=top><textarea rows=10 cols=90 name=qnote wrap=off>

กรอกข้อมูลที่นี่

[url]http://www.facebook.com/lampangdisaster[/url]

</textarea>

<br>' . $option_text . '</td></tr>

<tr><td>โดย</td>';

if ($program_type <> "puser") {

  echo "<td><input name=qname size=50 value=''>*";

} else {

  if (isset($_SESSION["puser"])) {

    echo "<td bgcolor=#ddffdd><input type=hidden name=qname size=50 value='". $_SESSION["puser"] ."'>";

    echo "<b>".$_SESSION["puser"];

  }

}

echo '</td></tr>

<tr><td>อีเมล</td><td><input name=qemail size=50></td></tr>

<tr><td valign=top>แนบแฟ้ม (upload)</td><td><input type=file name=upload>

<br>ประเภทของแฟ้มที่อนุญาตให้ upload คือ '.$allow_extension.'

</td></tr>

<tr><td valign=top><hr color=red><img src=?action=secure_code></td><td valign=top><hr color=red><input name=securecode size=10> นำตัวอักษรบนพื้นสีแดงมากรอกในช่องว่างนี้ (Security code)

<font color=gray><br>เพื่อป้องกันการกดซ้ำหลายครั้ง ต่อการส่งข้อมูล 1 ครั้ง</td></tr>

<tr><td colspan=2  align=center><input type=submit  name=action value="send_topic">

<input type=reset  name=reset value="reset"></td></tr></table>รณรงค์ให้ทุกท่านใช้ชื่อจริง .. เพื่อประโยชน์ในการประสานงาน และรวมกลุ่มในอนาคต</td></table></form>';

}

# ===============================

function view_topic() {

text_header();

global $dataroom,$can_reply,$header_reply,$table_width,$option_text,$allow_extension;

$z = preg_split("/[\s=]+/",$_SERVER['QUERY_STRING']);     

if (file_exists("$dataroom/".$z[1].".read")) {

  $ar=file("$dataroom/".$z[1].".read");

  $file=fopen("$dataroom/".$z[1].".read","w");

  fputs($file,$ar[0] + 1);        

} else {    

  $file=fopen("$dataroom/".$z[1].".read","w");

  fputs($file,"1");

}

fclose($file);

$z = preg_split("/[\s=]+/",$_SERVER['QUERY_STRING']);

echo "<form enctype='multipart/form-data' method=post action='?reply=". $z[1] ."' target=_top>";

$file = file("$dataroom/".$z[1].".htm");

for ($i=0;$i < count($file); $i++) echo str_replace(chr(9),"<dd>",$file[$i]);

echo '<center>';

if ($can_reply == "yes") {

echo '<br><br><table border=0 cellspacing=0 width='. $table_width .' bgcolor=#dddddd>

<tr bgcolor=#aaaaaa><td valign=top align=center colspan=2>'. $header_reply . '<tr><td valign=top>รายละเอียด</td><td><textarea rows=10 cols=80 name=qnote wrap=off></textarea>

<br>' . $option_text . '</td></tr>

<tr><td>โดย</td><td><input name=qname size=50></td></tr>

<tr><td>อีเมล</td><td><input name=qemail size=50></td></tr>

<tr><td valign=top>แนบแฟ้ม (upload)</td><td><input type=file name=upload>

<br>ประเภทของแฟ้มที่อนุญาตให้ upload คือ '.$allow_extension.'

<tr><td valign=top><hr color=blue><img src=?secure='; echo $z[1]; echo '></td><td><hr color=blue><input name=securecode size=10>นำตัวอักษรบนพื้นสีน้ำเงินมากรอกในช่องว่างนี้ (Security code)</td></tr>

<tr><td colspan=2 align=center><input type=submit  name=Submit value="ส่งข้อความ"><input type=Reset  name=Reset value=Clear></td></tr>

</table></form>';

}

text_footer();

}

# ===============================

function list_main() {

text_header();

global $can_reply,$title,$add_text,$dataroom,$titleperpage,$program_type,$can_search,$show_no,$icon_file,$show_header_tb,$show_writer,$table_width,$show_counter;

$file=file($dataroom."/topic.htm");

$show=count($file);

$n=$show;

if ($program_type == "puser") {

  user_login_form();

} else {

  if ($program_type <> "news") echo $add_text;

}

$k="";

if ($can_search == "yes") {

  echo "<table align=center><form action=? method=post><td><input size=8 name=keyword value='";

  if (isset($_POST['keyword'])) $k=$_POST['keyword'];

  echo $k."'><input type=submit value='สืบค้นจากหัวข้อ'></td></form></table>";

}

if (isset($_GET['pg'])) $pg = $_GET['pg']; else $pg = 1;

if (isset($_GET['tot'])) $tot = $_GET['tot']; else $tot = $titleperpage;

$pgcnt = round($n / $tot);

if(($n / $tot) > $pgcnt) { $pgcnt++; }

echo '<base target="_blank">';

if ($show_header_tb=="yes") {

  echo "<table align=center width=$table_width bgcolor=#88aabb><td><b><a href='?pg=1'>หน้า</a>: </b>";

  for ($i=1;$i<=$pgcnt;$i++) { 

    echo "<";

    if ($pg == $i) { echo "! "; }

    echo "a href='?pg=$i'>$i</a>.";

  }

  echo " <a href='?tot=$n'>ทั้งหมด</a></td><td align=right>($titleperpage หัวข้อ/หน้า)</td></table>";

}

$first = $tot * ($pg - 1) + 1;

$last = $tot * $pg;

echo "<center><table border=0 cellspacing=1 width=$table_width>";

if ($show_header_tb=="yes") {

  echo "<tr bgcolor=#aabbcc align=center>";

  if ($show_no == "yes") echo "<td width=30>ลำดับ</td>";

  echo "<td>หัวข้อ (Subject)</td>";

  if ($show_writer=="yes") echo "<td width=150>ชื่อผู้ตั้งหัวข้อ<br>เวลา และวันที่</td>";

  if ($show_counter=="yes") {

     echo "<td width=80>จำนวนที่<br>";

     if ($can_reply == "yes") echo "เขียน/";

	 echo "อ่าน</td>";

  }

  echo "</tr>";

}

for ($i=$show - 1; $i>=0; $i--) {

  $n--;

  $chkline = $show - $i;  

  if (strlen($k) > 0)  if (strlen(strpos($file[$i], $k)) == 0) continue;

  if (($chkline >= $first && $chkline <= $last) || strlen($k) > 0) {

    $z = preg_split("/[\s?]+/",$file[$i]);    

    $z = preg_split("/[\s']+/",$z[2]);     

    $z = preg_split("/[\s=]+/",$z[0]);     

    if (file_exists("$dataroom/$z[1].reply")) {

      $DATA=fopen("$dataroom/$z[1].reply" , "r");

      $num=fgets($DATA,3);

      if (strlen($k) > 0) echo "<tr bgcolor=#ffffdd>"; else

        if (($i % 2) == 0) echo "<tr bgcolor=#dddddd>"; else echo "<tr bgcolor=white>"; 

      if ($show_no == "yes") echo "<td align=right>".($i + 1)."</td>";

      if (file_exists($icon_file)) echo "<td><img src=$icon_file>"; else echo "<td>";

      $title_writer = explode('</td><td align=center>',$file[$i]);

      echo $title_writer[0];

	  if ($show_writer=="yes") echo "<td align=center>".$title_writer[1];

	  if ($show_counter=="yes") {    

	    echo "</td><td align=center>";

        if ($can_reply == "yes") {

          if ($num > 5) echo "<font color=blue>$num</font>/"; else echo $num."/";

        }

        if (file_exists("$dataroom/$z[1].read")) {

          $ar=file("$dataroom/$z[1].read");

          if ($ar[0] > 20) echo "<font color=blue>$ar[0]</font>"; else echo "$ar[0]";

        }

      }

	  echo "<a href='?d=".$z[1]."'>.</a><a href='?e=".$z[1]."'>.</a></td></tr>\n";

      fclose ($DATA); 

    }

  }

}

echo "</table>";

text_footer();

}

# ===============================

function reply_topic() {

text_header();

global $dataroom,$table_width,$allow_extension;

$z = preg_split("/[\s=]+/",$_SERVER['QUERY_STRING']);

# $k=filesize("$dataroom/".$z[1].".htm");

# $k=count($file) + $z[1];

# $k=fileatime("$dataroom/".$z[1].".htm") * $z[1] + filesize("$dataroom/".$z[1].".htm");

$k=fileatime("$dataroom/".$z[1].".htm") * filesize("$dataroom/".$z[1].".htm");

$key=ord(substr(crypt($k,$k),-1,1)) . ord(substr(crypt($k,$k),-2,1)); 

if ((strlen($_POST['qnote']) < 5) || (strlen($_POST['qname']) < 5) || ($key <> $_POST['securecode'])) {

  echo "<center><br><b>ข้อมูลอาจไม่ครบ หรือ Security code อาจผิดก็ได้<br>กรุณากรอกข้อมูลใหม่ด้วยค่ะ</b></center>";

} else { 

  $qnote= $_POST['qnote'];

  $qnote= str_replace("?","&#63",$qnote);

  $qnote= str_replace(chr(92),"#92;",$qnote);

  $qnote= str_replace("[img]","<img src=",$qnote); 

  $qnote= str_replace("[/img]",">",$qnote); 

  $qnote= str_replace("[url]","[ <a href=",$qnote); 

  $qnote= str_replace("[/url]",">คลิ๊กที่นี่ - เพื่อเปิดแหล่งข้อมูล</a> ]",$qnote); 

  $qnote= str_replace("#92;","&#92;",$qnote);

  $qname= $_POST['qname'];

  $qname = str_replace("?","&#63",$qname);

  $qemail= $_POST['qemail'];

  $qemail = str_replace("?","&#63",$qemail);

  $qnote= nl2br ($qnote);

  $qnote= stripslashes($qnote);

  $qname= stripslashes($qname);

  $qemail= stripslashes($qemail); 

  $date=date("h:ia (j/m/y)");

  #

  $file =fopen("$dataroom/". $z[1] .".reply" , "r");

  $num=fgets($file,10);

  fclose ($file);

  $num++;

  $file=fopen("$dataroom/". $z[1] .".reply" , "w");

  fputs($file,$num);

  fclose($file);

  # 

  # upload reply

  $ar_last_ext = explode(".",$_FILES['upload']['name']);  

  $found_ext = 0;

  if (count($ar_last_ext) > 1) {  

  $last_ext = $ar_last_ext[count($ar_last_ext) - 1]; 

  $ar = explode(",",$allow_extension);

  for ($i=0;$i<count($ar);$i++){

      if (strtolower($last_ext) == strtolower($ar[$i])) { $found_ext = 1; }

  }  

  if ($found_ext == 1) {

    $attach_file = $z[1] ."_". $num .".". strtolower($last_ext);

    copy($_FILES['upload']['tmp_name'],"$dataroom/$attach_file");

  }

  }

  #

  $file=fopen("$dataroom/".$z[1].".htm", "at");

  fputs($file,"<br><table border=0 cellspacing =0 width=" . $table_width . " bgcolor=#ffffdd align=center><tr><td valign=top align=center width=100 bgcolor=#dddddd>");

  fputs($file,"ความเห็นที่<br>".$num);

  fputs($file,"</td><td valign=top width=600>");

  if ($found_ext == 1) {

      fputs ($file , "ดาวน์โหลด : <a href=$dataroom/$attach_file>$attach_file</a><br>");

      if (strtolower($last_ext) == "jpg" || strtolower($last_ext) == "gif" || strtolower($last_ext) == "png") { fputs ($file , "<img src=$dataroom/$attach_file><br>"); }

  }

  fputs($file,"$qnote</td></tr>");

  fputs($file,"<tr><td align=right bgcolor=#808080 colspan=2><font color=white><b>โดย</b> : $qname <a href='mailto:$qemail'>$qemail</a> ");

  fputs($file,"$date<! ". $_SERVER["REMOTE_ADDR"] ."></td></tr></table>");

  fclose ($file);

  echo "<br><center><table border=0 cellspacing =0 width=90% bgcolor=white><tr><td>$qnote</td></tr>";

  echo "<tr><td align=right bgcolor=#dddddd><font color=green><b>โดย</b> : $qname <a href='mailto:$qemail'>$qemail</a><! ". $_SERVER["REMOTE_ADDR"] ."> ";

  echo " $date</font></td></tr></table><br><a href='?' target=_self>กลับหน้าหลัก</a></center>";

}

}

# ===============================

function secure_code_r() {

  global $dataroom;

  $z = explode("=",$_SERVER["QUERY_STRING"]);

  # $z = explode("=",$_SERVER["REQUEST_URI"]);

  # $k=filesize("$dataroom/".$z[1].".htm");

  # $k=fileatime("$dataroom/".$z[1].".htm") * $z[1] + filesize("$dataroom/".$z[1].".htm");

  $k=fileatime("$dataroom/".$z[1].".htm") * filesize("$dataroom/".$z[1].".htm");

  $key=ord(substr(crypt($k,$k),-1,1)) . ord(substr(crypt($k,$k),-2,1)); 

  header("Content-type: image/jpeg");

  $myImage = ImageCreate(80, 20);

  $white = ImageColorAllocate($myImage, 255, 255, 255);

  $red = ImageColorAllocate($myImage, 0 , 0, 255);   # blue color

  ImageFill($myImage, 0, 0, $red);

  Imagestring($myImage, 5, 2, 4, "$key", $white);

  Imageline($myImage,1,5,75,5,$white); 

  Imageline($myImage,1,17,75,17,$white); 

  Imagejpeg($myImage);

  Imagedestroy($myImage);   

}

# ===============================

function secure_code() {

global $dataroom;

  $file=file ($dataroom."/topic.htm");

  $k=count($file);

  $key=ord(substr(crypt($k,$k),-1,1)) . ord(substr(crypt($k,$k),-2,1)); 

  header("Content-type: image/jpeg");

  $myImage = ImageCreate(80, 20);

  $white = ImageColorAllocate($myImage, 255, 255, 255);

  $red = ImageColorAllocate($myImage, 255, 0, 0);   # red color

  ImageFill($myImage, 0, 0, $red);

  Imagestring($myImage, 5, 2, 4, "$key", $white);

  Imageline($myImage,1,5,75,5,$white); 

  Imageline($myImage,1,17,75,17,$white); 

  Imagejpeg($myImage);

  Imagedestroy($myImage); 

}

# ===============================

function delete_topic() {

text_header();

global $delete,$webmaster_password,$dataroom;

if (isset($_POST['securecode'])) {

  $file=file("$dataroom/topic.htm");

  $k=count($file);

  $key=ord(substr(crypt($k,$k),-1,1)) . ord(substr(crypt($k,$k),-2,1)); 

  if ($_POST['securecode'] == $key && $webmaster_password == $_POST['webmaster_password']) {

    $ar=file($dataroom."/topic.htm");

    $file=fopen($dataroom."/topic.htm","w");  

    for ($i=0;$i<count($ar);$i++) {

      $z = explode("view=",$ar[$i]);    

      $z = explode("'",$z[1]);  

      if ($z[0] <> $delete) {

        fputs($file,"$ar[$i]");

      } else {

        echo "<center><font size=6>Delete $delete : ok<br><a href='?'>Back to listing</a>";

      }   

    }

    fclose($file);

    unlink("$dataroom/".$delete.".htm");

    if (file_exists("$dataroom/".$delete.".read")) unlink("$dataroom/".$delete.".read");

    if (file_exists("$dataroom/".$delete.".reply")) unlink("$dataroom/".$delete.".reply");

  } else {

    echo "<center>รหัส secure และรหัส webmaster_password ไม่ถูกต้อง โปรดตรวจสอบใหม่";

  }

} else {

echo "<center><form action='?d=".$delete."' method=post target=_self>".'<table align=center bgcolor=#ffffdd><tr><td colspan=2>

<font size=6>เว็บเพจหน้านี้สำหรับผู้ดูแลเท่านั้น</td></tr>

<tr><td>รหัส secure <img src=?action=secure_code>=&gt;</td><td><input name=securecode size=10>นำตัวอักษรบนพื้นสีแดงมากรอกในช่องว่างนี้ (Security code)</td></tr>

<tr><td>$webmaster_password =&gt;</td><td><input type=password name=webmaster_password size=10></td></tr>

<tr><td colspan=2><input type=submit value=ยืนยันการลบหัวข้อ></td></tr></table>

</form>';

}

}

# ===============================

function edit_topic() {

text_header();

global $edit,$edit_topic_password,$dataroom;

if (isset($_POST['securecode'])) {

  $file=file("$dataroom/topic.htm");

  $k=count($file);

  $key=ord(substr(crypt($k,$k),-1,1)) . ord(substr(crypt($k,$k),-2,1)); 

  if ($_POST['securecode'] == $key && $edit_topic_password == $_POST['edit_topic_password']) {

    $file=fopen($dataroom."/".$edit.".htm","w");  

    fputs($file,$_POST['qnote']);

    fclose($file);

    echo "<center>แก้ไขเรียบร้อย<br><a href='?' target=_self>กลับหน้าหลัก</a>";  

  } else {

    echo "<center>รหัส secure และรหัส edit_topic_password ไม่ถูกต้อง โปรดตรวจสอบใหม่";

  }

} else {

echo "<center><form action='?e=".$edit."' method=post target=_self>"."<table align=center bgcolor=#ffdddd><tr><td colspan=2 align=center>

<font size=6>เว็บเพจหน้านี้สำหรับผู้ดูแลเท่านั้น</td></tr>

<tr><td align=right>รหัส secure <img src=?action=secure_code>=&gt;</td><td><input name=securecode size=10>นำตัวอักษรบนพื้นสีแดงมากรอกในช่องว่างนี้ (Security code)</td></tr>

<tr><td align=right>edit_topic_password =&gt;</td><td><input type=password name=edit_topic_password size=10></td></tr>

<tr><td colspan=2>

<textarea rows=15 cols=90 name=qnote>";

$ear=file("$dataroom/".$edit.".htm");

for ($i=0;$i<count($ear);$i++) {

echo $ear[$i];

}

echo '</textarea></td></tr>

<tr><td colspan=2 align=center><input type=submit value=ยืนยันการแก้ไขหัวข้อ></td></tr></table>

</form>';

}

}

# ===============================

function user_login_form() {

global $add_text;

echo "<table width=98% bgcolor=white><form action='' method=post>";

if (!isset($_SESSION["puser"]) || strlen($_SESSION["puser"]) < 1) {

echo "<td><b>ระบบ Login</b>

<br>สำหรับผู้มีสิทธิ์<br>ผู้อ่านทั่วไปไม่จำเป็นต้อง Login

<td>User :<td><input name=puser>

<td>Password :<td><input name=ppassword type=password>

<td valign=middle><br><input type=submit value=login name=login>";

} else {

echo "<td><b>ยินดีต้อนรับ<b> : ". $_SESSION["puser"] . "<br>". $add_text ."

<td valign=middle><br><input type=submit value=logout name=logout>";

}

echo "</form></table>";

}

# ===============================

function text_header() {

global $title,$bgcolor,$show_header,$have_header,$file_header,$header;

if (file_exists($file_header))

require($file_header); else {

if ($have_header == "yes") {

echo '<html><head><meta http-equiv=content-type content="text/html; charset=windows-874">

<meta name=keywords content="webboard,opinion,forum"><meta name=description content="'; 

echo $title; 

echo '"><title>'; 

echo $title; echo '</title><style type="text/css">

body{scrollbar-base-color:gray;scrollbar-arrow-color:yellow;font-family:microsoft sans serif;font-size:10pt}

a:link{color:red;text-decoration:none;}

a:visited{color:purple;text-decoration:underline;}

a:hover{color:blue;text-decoration:none;background-color:#ffffdd;}

td{font-size:10pt;font-family:microsoft sans serif;}

textarea{font-size:10pt;font-family:microsoft sans serif;}

</style><body bgcolor=#'; echo $bgcolor; echo ' leftmargin=0 topmargin=0>';

}

if ($show_header == "yes") echo $header;

}

}

# ===============================

function text_footer() {

global $footer,$show_footer,$file_footer;

if (file_exists($file_footer))

require($file_footer); else {

if ($show_footer == "yes") echo $footer;

}

exit;

}

# ===============================

function startup_firsttime() {

global $dataroom;

mkdir("$dataroom",0755);

$file=fopen($dataroom."/topic.htm","w");

fclose ($file);

$file=fopen($dataroom."/number.txt","w");

fputs ($file,"0");

fclose ($file);

echo '<html><head><meta http-equiv=content-type content="text/html; charset=windows-874">';

echo '<meta http-equiv=refresh content="30;url=?pg=1"><center>โปรมนี้ถูกติดตั้ง โดยการสร้างห้อง ';

echo $dataroom;

echo ' ในห้องนี้เพื่อเก็บข้อมูล<br>สร้างแฟ้ม topic.htm ไว้เก็บข้อมูล<br>สร้างแฟ้ม number.txt ไว้เก็บเลขหัวข้อล่าสุด';

echo '<hr color="red">โปรดรอประมาณ 30 วินาที<br>เพื่อเข้าสู่ <a href="?pg=1">หน้าแรก</a> ของระบบ';

}

?>

จำนวน : 659 บรรทัด
าษาเฮชทีเอ็มแอล (HTML = HyperText Markup Language) คือ ภาษาคอมพิวเตอร์ที่ออกแบบมาเพื่อใช้ในการสร้างเว็บเพจที่เรียกดูผ่านทางเว็บเบราว์เซอร์ (Web Browser) เริ่มพัฒนาโดย ทิม เบอร์เนอรส์ ลี (Tim Berners Lee) ในปัจจุบัน HTML ล่าสุดคือ รุ่น 5 เป็นมาตรฐานหนึ่งของ ISO ซึ่งจัดการโดย World Wide Web Consortium (W3C) ในปัจจุบัน ทาง W3C ผลักดัน รูปแบบของ HTML แบบใหม่ ที่เรียกว่า XHTML รุ่นแรกคือ 1.0 (ม.ค.2543) ซึ่งมีโครงสร้างเป็นแบบ XML (eXtensible Markup Language)
าษาพีเอชพี (PHP Language) คือ ภาษาคอมพิวเตอร์ประเภทโอเพนท์ซอร์ท (Open Source Computer Language) สำหรับพัฒนาเว็บเพจแบบไดนามิก เมื่อเครื่องบริการได้รับคำร้องจากผู้ใช้ก็จะส่งให้กับ ตัวแปลภาษา ทำหน้าที่ประมวลผลและส่งข้อมูลกลับไปยังเครื่องของผู้ใช้ที่ร้องขอ ในรูปเอชทีเอ็มแอล ภาพ หรือแฟ้มดิจิทอลอื่นใด ลักษณะของภาษามีรากฐานคำสั่งมาจากภาษาซี เป็นภาษาที่สามารถพัฒนาให้ใช้งานแบบโต้ตอบกับผู้ใช้ได้
าษาไพทอน (Python Language) คือ ภาษาคอมพิวเตอร์ประเภทโอเพนท์ซอร์ท (Open Source Computer Language) สำหรับพัฒนาแอพพลิเคชั่นโดยไม่ยึดติดกับแพลตฟอร์ม (Platform) และใช้ในงานได้หลายประเภท ทั้งใช้ในการประมวลผลผ่านคอมมานด์ไลน์ หรือเป็นเว็บเพจแบบไดนามิก เมื่อเครื่องบริการได้รับคำร้องจากผู้ใช้ก็จะส่งให้โค้ดให้กับตัวแปลภาษา เพื่อทำหน้าที่ประมวลผลและส่งข้อมูลกลับไปยังเครื่องของผู้ใช้ที่ร้องขอ ในรูปข้อความ เอชทีเอ็มแอล ภาพ หรือแฟ้มดิจิทอลอื่นใด ลักษณะของภาษามีรากฐานคำสั่งมาจากภาษาซี เป็นภาษาที่สามารถพัฒนาให้ใช้งานแบบโต้ตอบกับผู้ใช้ได้ จุดที่แตกต่างกับภาษาอื่น คือ การรวบรวมจุดเด่นของแต่ละภาษามารวมเข้าด้วยกัน
อสคิวแอล (SQL = Structured Query Language) คือ ภาษาสอบถามข้อมูล หรือภาษาจัดการข้อมูลอย่างมีโครงสร้าง มีการพัฒนาภาษาคอมพิวเตอร์ และโปรแกรมฐานข้อมูลที่รองรับมากมาย เพราะจัดการข้อมูลได้ง่าย เช่น MySQL, MariaDB, MsSQL, PostgreSQL หรือ MS Access เป็นต้น สำหรับโปรแกรมฐานข้อมูลที่ได้รับความนิยมคือ MySQL หรือ MariaDB เป็น Open Source ที่ใช้งานได้ทั้งใน Linux และ Windows
วัสดีชาวโลก (Hello World) คือ ผลลัพธ์ครั้งแรกที่นักพัฒนาโปรแกรมนิยมเลือกใช้แสดงผลในโปรแกรมแรกที่เขียนขึ้นเพื่อทดสอบการทำงาน ข้อความนี้ทำให้นึกถึงมนุษย์ต่างดาวที่มาเยือนโลกและกล่าวกับมนุษย์เมื่อพบกันครั้งแรกในภาพยนตร์
ตัวอย่าง Hello World
ปรับปรุงโปรแกรม source.pl : 2565-07-24
rspsocial
Thaiall.com