php ajax 留言板_PHP教程

來源:互聯網
上載者:User
php ajax 留言板提供一款國人寫的php ajax 留言板,他是利用了jquery php mysql ajax來實現php ajax 局部重新整理留方板執行個體的喜歡就下載吧。

php教程 ajax 留言板
提供一款國人寫的php ajax 留言板,他是利用了jquery php mysql教程 ajax來實現php ajax 局部重新整理留方板執行個體的喜歡就下載吧。
*/
$link = @mysql_connect($db_host,$db_user,$db_pass) or die('unable to establish a db connection');

mysql_query("set names 'utf8'");
mysql_select_db($db_database,$link);

class comment
{
private $data = array();

public function __construct($row)
{
/*
/ the constructor
*/

$this->data = $row;
}

public function markup()
{
/*
/ this method outputs the xhtml markup of the comment
*/

// setting up an alias, so we don't have to write $this->data every time:
$d = &$this->data;

$link_open = '';
$link_close = '';

if($d['url']){

// if the person has entered a url when adding a comment,
// define opening and closing hyperlink tags

$link_open = '';
$link_close = '';
}

// converting the time to a unix timestamp:
$d['dt'] = strtotime($d['dt']);

// needed for the default gravatar image:
$url = 'http://'.dirname($_server['server_name'].$_server["request_uri"]).'/img/default_avatar.gif';

return '



'.$link_open.'

'.$link_close.'


'.$link_open.$d['name'].$link_close.'
'.date('d m y',$d['dt']).'

'.$d['body'].'



';
}

public static function validate(&$arr)
{
/*
/ this method is used to validate the data sent via ajax.
/
/ it return true/false depending on whether the data is valid, and populates
/ the $arr array passed as a paremter (notice the ampersand above) with
/ either the valid input data, or the error messages.
*/

$errors = array();
$data = array();

// using the filter_input function introduced in php 5.2.0

if(!($data['email'] = filter_input(input_post,'email',filter_validate_email)))
{
$errors['email'] = 'please enter a valid email.';
}

if(!($data['url'] = filter_input(input_post,'url',filter_validate_url)))
{
// if the url field was not populated with a valid url,
// act as if no url was entered at all:

$url = '';
}

// using the filter with a custom callback function:

if(!($data['body'] = filter_input(input_post,'body',filter_callback,array('options'=>'comment::validate_text'))))
{
$errors['body'] = 'please enter a comment body.';
}

if(!($data['name'] = filter_input(input_post,'name',filter_callback,array('options'=>'comment::validate_text'))))
{
$errors['name'] = 'please enter a name.';
}

if(!empty($errors)){

// if there are errors, copy the $errors array to $arr:

$arr = $errors;
return false;
}

// if the data is valid, sanitize all the data and copy it to $arr:

foreach($data as $k=>$v){
$arr[$k] = mysql_real_escape_string($v);
}

// ensure that the email is lower case:

$arr['email'] = strtolower(trim($arr['email']));

return true;

}

private static function validate_text($str)
{
/*
/ this method is used internally as a filter_callback
*/

if(mb_strlen($str,'utf8')<1)
return false;

// encode all html special characters (<, >, ", & .. etc) and convert
// the new line characters to
tags:

$str = nl2br(htmlspecialchars($str));

// remove the new line characters that are left
$str = str_replace(array(chr(10),chr(13)),'',$str);

return $str;
}

}

$comments = array();
$result = mysql_query("select * from comments order by id asc");

while($row = mysql_fetch_assoc($result))
{
$comments[] = new comment($row);
}

?>





simple ajax commenting system | tutorialzine demo


/*
/ output the comments one by one:
*/

foreach($comments as $c){
echo $c->markup();
}

?>


add a comment





資料庫教程結構

--
-- table structure for table `comments`
--

create table `comments` (
`id` int(10) unsigned not null auto_increment,
`name` varchar(128) collate utf8_unicode_ci not null default '',
`url` varchar(255) collate utf8_unicode_ci not null default '',
`email` varchar(255) collate utf8_unicode_ci not null default '',
`body` text collate utf8_unicode_ci not null,
`dt` timestamp not null default '0000-00-00',
primary key (`id`)
) engine=myisam default charset=utf8 collate=utf8_unicode_ci;

源碼下載

http://down.php100.com/down/code/php/liuyanboke/2010/1028/21479.html


http://www.bkjia.com/PHPjc/444830.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444830.htmlTechArticlephp ajax 留言板提供一款國人寫的php ajax 留言板,他是利用了jquery php mysql ajax來實現php ajax 局部重新整理留方板執行個體的喜歡就下載吧。 php教程 ajax...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.