| |
Steps to install a simple PHP WAP forum on your
WAP-enabled sites.
- Go to CPanel home and select
.
Enter new database: forum and click "Create
Database".
Enter username: forum password: 123456
and click "Create User"
Select user: ***_forum as well as database:
***_forum and click "Add User To Database". Note: *** from
***_forum indicates the username used to log in into CPanel.
If a user is added into the database successfully,
you will see as shown above.
- Select "phpMyAdmin" which is located at the bottom
of the same page.
Select your database for example ***_forum
(0).
- After that, choose
. You
will see a form as shown below:
- Before you copy and paste the text as shown below
into the form above and click "Go", please don't forget to change the
combine_forum.SForum to your ***_forum.SForum , otherwise the table
won't work!!!
CREATE TABLE combine_forum.SForum ( id int(10)
unsigned NOT NULL auto_increment primary key, wid int(10) unsigned
NOT NULL default '0', for_ptitle varchar(255) NOT NULL default
'', for_text text NOT NULL, for_mail varchar(255) NOT NULL default
'', for_data datetime NOT NULL default '0000-00-00
00:00:00', for_dataw datetime NOT NULL default '0000-00-00
00:00:00', for_ip varchar(15) NOT NULL default
'000.000.000.000', for_name varchar(255) NOT NULL default '', KEY
wid(wid) ) TYPE=MyISAM;
-
Place the following code as index.php in a
newly created directory, for example "forum".
<html>
<head> <meta
http-equiv="Content-Type" content="text/html;
charset=windows-1252"> <?php require_once("SForum_class.php"); require_once("email_validation.php");
$validator=new
email_validation_class;
$forum->Show_SFname();
$forum->Main_page(); print("<br><br>\n");
if
(isset($_POST['submit'])) { $for_mail = $_POST['frm_mail']; if
(!empty($_POST['frm_mail'])) { $valmail =
$validator->ValidateEmailAddress($_POST['frm_mail']); if ($valmail
== 0) { echo "Your mail was invalid so was
droped!<br><br>\n"; $for_mail = ""; // if mail invalid
then
dropped } }
$forum->Add_new_post($_POST['frm_ptitle'],$_POST['frm_text'],$for_mail,$_POST['frm_ip'],$_POST['frm_name'],$_POST['frm_wid']); }
if
(isset($_GET['wid']))
{ #phpinfo(); $forum->Show_SForum_Threads($_GET['wid']); $forum->pansw
= $_GET['wid']; } else
{ $forum->Show_SForum(); $forum->pansw =
0; }
$forum->Show_frm($forum->ptitle);
print("\n"); $forum->Main_page(); print("<P><font
face=\"Arial\" size=\"1\">Powered by: <a
href=\"http://wapnews.mobi/wapforuminstall.php\">WapNews.mobi</a></font>\n"); ?> </body>
</html>
- Place the following code as SForum_class.php
in the same directory, for example "forum".
<?php
class SForum { var $SFname =
"Simple Wap Forum"; var $ptitle; var $react; // number of answers
in a thread var $pansw; var $title;
// SForum: constructor,
connecting to DB function SForum() { $this->ptitle =
NULL; $this->pansw = 0; $this->title =
"<TITLE>$this->SFname</TITLE>"; print($this->title); echo
"\n</head>"; echo "\n\n<body>\n"; echo "<font
face=\"Arial\" size=\"1\"><font face=\"Arial\"
size=\"1\">"; include_once("config.php"); // DB Config
Data $pol = mysql_connect($dbhost,$dbuname,$dbpass) or die ("Couldn't
connect to server.<br>\n"); $db = mysql_select_db($dbname,$pol)
or die ("Couldn't connect to database.<br>\n"); }
//
Show_frm: displays the form function Show_frm($ptitle=NULL)
{ if(!empty($ptitle)) { $this->ptitle = "Re:
".$ptitle; } $zawartosc = "\n\n<FORM
ACTION=\"".$_SERVER['PHP_SELF']."\" METHOD=\"post\"
NAME=\"frm\">\n" . "\n" . "Title:<BR><INPUT
TYPE=\"text\" NAME=\"frm_ptitle\" VALUE=\"$this->ptitle\"
SIZE=\"17\"></BR>\n" . "\n" .
"Text:<BR><TEXTAREA NAME=\"frm_text\" cols=\"14\"
rows=\"5\"></TEXTAREA></BR>\n" . "\n" .
"Nick:<BR><INPUT TYPE=\"text\" NAME=\"frm_name\"
VALUE=\"Guest\" onfocus=\"this.value=''\"
SIZE=\"17\"></BR>\n" . "\n" .
"Email(Optional):<BR><INPUT TYPE=\"text\" NAME=\"frm_mail\"
VALUE=\"\" SIZE=\"17\"></BR>\n" . "\n" . "<INPUT
TYPE=\"submit\" NAME=\"submit\" VALUE=\"Post\">\n" . "\n" .
"<INPUT TYPE=\"hidden\" NAME=\"frm_ip\"
VALUE=\"".$_SERVER['REMOTE_ADDR']."\">\n" . "<INPUT
TYPE=\"hidden\" NAME=\"frm_wid\"
VALUE=\"".$this->pansw."\">\n" .
"</FORM>\n\n"; print($zawartosc); }
// Show_SFname :
Show SForum name as text function Show_SFname()
{ print("$this->SFname<P>\n"); }
// Add_new_post:
Adds new record to DB function
Add_new_post($ptitle,$text,$mail,$ip,$name,$frm_wid) { if($ptitle==""
or $text==""){ return; } $this->ptitle =
addslashes(htmlspecialchars(trim($ptitle))); $this->text =
addslashes(htmlspecialchars(trim($text)));
if ($frm_wid == 0)
{ $zapytanie = "INSERT INTO SForum
(wid,for_ptitle,for_text,for_mail,for_data,for_dataw,for_ip,for_name)
VALUES('$frm_wid', '$this->ptitle', '$this->text', '$mail', now(),
now(), '$ip', '$name')"; $sql = mysql_query($zapytanie) or die
(mysql_error()); } else { $zapytanie = "INSERT INTO SForum
(wid,for_ptitle,for_text,for_mail,for_data,for_ip,for_name)
VALUES('$frm_wid', '$this->ptitle', '$this->text', '$mail', now(),
'$ip', '$name')"; $sql = mysql_query($zapytanie) or die
(mysql_error()); } $id = mysql_insert_id(); if ($frm_wid == 0)
{ $zapytanie = "UPDATE SForum SET wid='$id' WHERE
id='$id'"; #print $zapytanie; $sql = mysql_query($zapytanie) or
die (mysql_error()); } else { $zapytanie = "UPDATE SForum SET
for_dataw=now() WHERE id='$frm_wid'"; #print $zapytanie; $sql =
mysql_query($zapytanie) or die (mysql_error()); }
}
//
Show_SForum: Displays the main message of threads function
Show_SForum() { $sql = 'SELECT * FROM SForum WHERE id=wid ORDER BY
for_dataw DESC'; #print $sql."<br>\n"; $sql =
mysql_query($sql) or die (mysql_error()); $iledokumentow =
mysql_affected_rows(); if ($iledokumentow > 0)
{ print("\n"); while ($row = mysql_fetch_array($sql)) { $sql1 =
"SELECT COUNT(wid)-1 AS num FROM SForum WHERE wid=".$row['id']." GROUP
BY wid"; #print $sql1."<br>\n"; $sql1 = mysql_query($sql1)
or die (mysql_error()); $row1 = mysql_fetch_array($sql1); //number
of reactions $this->react=$row1['num']; if ($row['for_name'] ==
"") { $row['for_name'] = "Guest"; } $this->ptitle =
stripslashes($row['for_ptitle']); print("<A
HREF=\"".$_SERVER['PHP_SELF']."?wid=".$row['id']."\">".$this->ptitle."</A>
| replies: ".$this->react." | ".$row['for_name']." |
".$row['for_dataw']."<hr border=0
size=1>\n\n"); } unset($this->react); print("\n"); }
else { print("No threads<br>\n"); } $this->ptitle =
""; //the new thread's title is empty } // Show_SForum_Threads:
Displays all messages of a thread function Show_SForum_Threads($wid)
{ //$this->pansw = $wid; $zapytanie = "SELECT * FROM SForum
WHERE wid='$wid' ORDER BY for_data ASC"; //print $zapytanie; $sql
= mysql_query($zapytanie) or die (mysql_error()); $iledokumentow =
mysql_affected_rows(); if ($iledokumentow > 0)
{ print("\n"); while ($row = mysql_fetch_array($sql))
{ $this->ptitle =
stripslashes($row['for_ptitle']); $this->text =
nl2br(stripslashes($row['for_text'])); if ($row['for_name'] == "")
{ $row['for_name'] = "Guest"; } if ($row['for_mail'] !== "")
{ $pmail = "<A
HREF=\"mailto:".$row['for_mail']."\">"; $kmail =
"</a>"; } else { $pmail = NULL; $kmail =
NULL; } print("<b><font face=\"Arial\"
size=\"2\">".$this->ptitle."</font></b><br><U>$pmail".$row['for_name']."$kmail</U>
|
".$row['for_data']."\n\n"); print("<br>".$this->text."<hr
noshade width=\"100%\" size=\"1\">\n\n"); } print("\n"); }
else { print("No threads<br>\n"); } $zapytanie = "SELECT
* FROM SForum WHERE id='$wid' LIMIT 0,1"; $sql =
mysql_query($zapytanie) or die (mysql_error()); $row =
mysql_fetch_array($sql); $this->ptitle =
stripslashes($row['for_ptitle']); //Re title for form }
//
Main_page: Show back-to-main link function Main_page()
{ print("<A HREF=\"".$_SERVER['PHP_SELF']."\">Go to Main
Page</A>\n"); echo "</font>"; } }
if
(!isset($forum)) { $forum = new SForum; } ?>
- Place the following code as
email_validation.php in the same directory, for example
"forum".
<?php /* * email_validation.php * *
@(#) $Header:
/home/mlemos/cvsroot/emailvalidation/email_validation.php,v 1.23
2005/09/16 18:20:58 mlemos Exp $ * */
class
email_validation_class { var
$email_regular_expression="^([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,6}\$"; var
$timeout=0; var $data_timeout=0; var $localhost=""; var
$localuser=""; var $debug=0; var $html_debug=0; var
$exclude_address=""; var $getmxrr="GetMXRR";
var
$next_token=""; var $preg; var $last_code="";
Function
Tokenize($string,$separator="") { if(!strcmp($separator,"")) { $separator=$string; $string=$this->next_token; } for($character=0;$character<strlen($separator);$character++) { if(GetType($position=strpos($string,$separator[$character]))=="integer") $found=(IsSet($found)
? min($found,$position) :
$position); } if(IsSet($found)) { $this->next_token=substr($string,$found+1); return(substr($string,0,$found)); } else { $this->next_token=""; return($string); } }
Function
OutputDebug($message) { $message.="\n"; if($this->html_debug) $message=str_replace("\n","<br
/>\n",HtmlEntities($message)); echo
$message; flush(); }
Function
GetLine($connection) { for($line="";;) { if(feof($connection)) return(0); $line.=fgets($connection,100); $length=strlen($line); if($length>=2 &&
substr($line,$length-2,2)=="\r\n") { $line=substr($line,0,$length-2); if($this->debug) $this->OutputDebug("S
$line"); return($line); } } }
Function
PutLine($connection,$line) { if($this->debug) $this->OutputDebug("C
$line"); return(fputs($connection,"$line\r\n")); }
Function
ValidateEmailAddress($email) { if(IsSet($this->preg)) { if(strlen($this->preg)) return(preg_match($this->preg,$email)); } else { $this->preg=(function_exists("preg_match")
? "/".str_replace("/", "\\/", $this->email_regular_expression)."/" :
""); return($this->ValidateEmailAddress($email)); } return(eregi($this->email_regular_expression,$email)!=0); }
Function
ValidateEmailHost($email,&$hosts) { if(!$this->ValidateEmailAddress($email)) return(0); $user=$this->Tokenize($email,"@"); $domain=$this->Tokenize(""); $hosts=$weights=array(); $getmxrr=$this->getmxrr; if(function_exists($getmxrr) &&
$getmxrr($domain,$hosts,$weights)) { $mxhosts=array(); for($host=0;$host<count($hosts);$host++) $mxhosts[$weights[$host]]=$hosts[$host]; KSort($mxhosts); for(Reset($mxhosts),$host=0;$host<count($mxhosts);Next($mxhosts),$host++) $hosts[$host]=$mxhosts[Key($mxhosts)]; } else { if(strcmp($ip=@gethostbyname($domain),$domain) &&
(strlen($this->exclude_address)==0 ||
strcmp(@gethostbyname($this->exclude_address),$ip))) $hosts[]=$domain; } return(count($hosts)!=0); }
Function
VerifyResultLines($connection,$code) { while(($line=$this->GetLine($connection))) { $this->last_code=$this->Tokenize($line,"
-"); if(strcmp($this->last_code,$code)) return(0); if(!strcmp(substr($line,
strlen($this->last_code), 1),"
")) return(1); } return(-1); }
Function
ValidateEmailBox($email) { if(!$this->ValidateEmailHost($email,$hosts)) return(0); if(!strcmp($localhost=$this->localhost,"") &&
!strcmp($localhost=getenv("SERVER_NAME"),"") &&
!strcmp($localhost=getenv("HOST"),"")) $localhost="localhost"; if(!strcmp($localuser=$this->localuser,"") &&
!strcmp($localuser=getenv("USERNAME"),"") &&
!strcmp($localuser=getenv("USER"),"")) $localuser="root"; for($host=0;$host<count($hosts);$host++) { $domain=$hosts[$host]; if(ereg('^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$',$domain)) $ip=$domain; else { if($this->debug) $this->OutputDebug("Resolving
host name
\"".$hosts[$host]."\"..."); if(!strcmp($ip=@gethostbyname($domain),$domain)) { if($this->debug) $this->OutputDebug("Could
not resolve host name
\"".$hosts[$host]."\"."); continue; } } if(strlen($this->exclude_address) &&
!strcmp(@gethostbyname($this->exclude_address),$ip)) { if($this->debug) $this->OutputDebug("Host
address of \"".$hosts[$host]."\" is the exclude
address"); continue; } if($this->debug) $this->OutputDebug("Connecting
to host address \"".$ip."\"..."); if(($connection=($this->timeout
? @fsockopen($ip,25,$errno,$error,$this->timeout) :
@fsockopen($ip,25)))) { $timeout=($this->data_timeout ?
$this->data_timeout :
$this->timeout); if($timeout &&
function_exists("socket_set_timeout")) socket_set_timeout($connection,$timeout,0); if($this->debug) $this->OutputDebug("Connected."); if($this->VerifyResultLines($connection,"220")>0 &&
$this->PutLine($connection,"HELO $localhost") &&
$this->VerifyResultLines($connection,"250")>0 &&
$this->PutLine($connection,"MAIL FROM:
<$localuser@$localhost>") &&
$this->VerifyResultLines($connection,"250")>0 &&
$this->PutLine($connection,"RCPT TO: <$email>") &&
($result=$this->VerifyResultLines($connection,"250"))>=0) { if($result) { if($this->PutLine($connection,"DATA")) $result=($this->VerifyResultLines($connection,"354")!=0); } else { if(strlen($this->last_code) &&
!strcmp($this->last_code[0],"4")) $result=-1; } if($this->debug) $this->OutputDebug("This
host states that the address is ".($result ? ($result>0 ? "valid" :
"undetermined") : "not
valid")."."); fclose($connection); if($this->debug) $this->OutputDebug("Disconnected."); return($result); } if($this->debug) $this->OutputDebug("Unable
to validate the address with this
host."); fclose($connection); if($this->debug) $this->OutputDebug("Disconnected."); } else { if($this->debug) $this->OutputDebug("Failed."); } } return(-1); } };
?>
- Before placing the following code as
config.php in the same directory as mentioned early, change the
value accordingly. Change combine_forum to your ***_forum
<?php /* * Config file for
SForum */
$dbhost = 'localhost'; // DB Host $dbuname =
'combine_forum'; // DB Username $dbpass = '123456'; // DB
Password $dbname = 'combine_forum'; // DB Name
?>
- Execute the index.php, then you are done!!!
|
|