当前位置: 编程技术>php
本页文章导读:
▪使用sockets:从新闻组中获取文章(三)
读取文章 既然我们已经得到了最后一篇文章的文章编号,读取最后的十篇文章就是很容易的事了。RFC977中说,ARTICLE命令既可以使用文章编号,也可以使用它的消息ID. 这里要注.........
▪PHP+MYSQL的文章管理系统(二)
###############index.php###################### <?session_start(); require"./inc/func.php"; mscon(); require "./inc/header.inc"; ?> <script language="javascript"> function opwin(filename) { window.open("read.........
▪使用sockets:从新闻组中获取文章(二)
与服务器对话 现在我们已经连接到了服务器,可以通过前面打开的socket同服务器对话了。比如说我们要从某个新闻组得到最近的10篇文章。RFC977指出,第一步要用GROUP命令选择正确的新.........
[1]使用sockets:从新闻组中获取文章(三)
来源: 互联网 发布时间: 2013-11-30
读取文章
既然我们已经得到了最后一篇文章的文章编号,读取最后的十篇文章就是很容易的事了。RFC977中说,ARTICLE命令既可以使用文章编号,也可以使用它的消息ID.
这里要注意,文章编号跟它的消息ID是不同的,因为每个新闻服务器分配自己的文章编号,所以同一篇文章在两个不同的服务器上的编号是不一样的,而文章的消息ID,是包括在文章的头信息里,并且是唯一的。
<?php
$cfgLimit =10;
//upload last articles
$boucle = $last-$cfgLimit;
while ($boucle<=$last) {
set_time_limit(0);
fputs($usenet_handle, "ARTICLE $bouclen");
$article="";
$tmp=fgets($usenet_handle, 4069);
if(substr($tmp,0,3) != "220") {
echo "+----------------------+n";
echo "Error on article $bouclen";
echo "+----------------------+n";
}
else {
while($tmp!=".rn") {
$tmp = fgets($usenet_handle, 4096);
$article .=$tmp;
}
echo "+----------------------+n";
echo "Article $bouclen";
echo "+----------------------+n";
echo "$articlen";
}
$boucle++;
}
?>
我们从服务器的这个新闻组中读取了最后的十篇文章,。也可以通过使用HEAD命令读取文章的头信息,或者使用BODY命令读取文章内容。
关闭连接
最后,通过调用fclose()函数关闭socket,结束同NNTP服务器的对话。
<?php
//close connection
fclose($usenet_handle);
?>
关于fclose()的更多信息,请参考 http://www.php.net/manual/function.fclose.php
结论
在上文中,我们看到了怎样打开、使用然后关闭一个socket:连接到一个NNTP服务器,取回一些文章。使用POST命令发表文章也复杂不到哪儿去。
下一步就是编写一个基于WEB的新闻组客户端了。
存储这些文章,用某个搜索引擎(比如说http://www.htdig.org)对文章进行索引也是非常容易的。这样,你有了一个基于web的搜索新闻组的程序了。
这样的程序的一个例子可以在http://www.phpindex.com/ng/得到。
既然我们已经得到了最后一篇文章的文章编号,读取最后的十篇文章就是很容易的事了。RFC977中说,ARTICLE命令既可以使用文章编号,也可以使用它的消息ID.
这里要注意,文章编号跟它的消息ID是不同的,因为每个新闻服务器分配自己的文章编号,所以同一篇文章在两个不同的服务器上的编号是不一样的,而文章的消息ID,是包括在文章的头信息里,并且是唯一的。
<?php
$cfgLimit =10;
//upload last articles
$boucle = $last-$cfgLimit;
while ($boucle<=$last) {
set_time_limit(0);
fputs($usenet_handle, "ARTICLE $bouclen");
$article="";
$tmp=fgets($usenet_handle, 4069);
if(substr($tmp,0,3) != "220") {
echo "+----------------------+n";
echo "Error on article $bouclen";
echo "+----------------------+n";
}
else {
while($tmp!=".rn") {
$tmp = fgets($usenet_handle, 4096);
$article .=$tmp;
}
echo "+----------------------+n";
echo "Article $bouclen";
echo "+----------------------+n";
echo "$articlen";
}
$boucle++;
}
?>
我们从服务器的这个新闻组中读取了最后的十篇文章,。也可以通过使用HEAD命令读取文章的头信息,或者使用BODY命令读取文章内容。
关闭连接
最后,通过调用fclose()函数关闭socket,结束同NNTP服务器的对话。
<?php
//close connection
fclose($usenet_handle);
?>
关于fclose()的更多信息,请参考 http://www.php.net/manual/function.fclose.php
结论
在上文中,我们看到了怎样打开、使用然后关闭一个socket:连接到一个NNTP服务器,取回一些文章。使用POST命令发表文章也复杂不到哪儿去。
下一步就是编写一个基于WEB的新闻组客户端了。
存储这些文章,用某个搜索引擎(比如说http://www.htdig.org)对文章进行索引也是非常容易的。这样,你有了一个基于web的搜索新闻组的程序了。
这样的程序的一个例子可以在http://www.phpindex.com/ng/得到。
[2]PHP+MYSQL的文章管理系统(二)
来源: 互联网 发布时间: 2013-11-30
###############index.php######################
<?session_start();
require"./inc/func.php";
mscon();
require "./inc/header.inc";
?>
<script language="javascript">
function opwin(filename)
{ window.open("read_article.php?id="+filename,"","height=500,width=585,resizable=no,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#003399" height="23">
<tr>
<td width="80">
<div id="Layer2" ><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="80" height="60">
<param name=movie value="images/logo.swf">
<param name=quality value=high>
<param name="wmode" value="transparent">
<embed src="/blog_article/images/logo.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="80" height="60" wmode="transparent">
</embed>
</object></div>
<div id="Layer1" ><img src="/blog_article/images/11.gif" width="58" height="55"></div>
</td>
<td width="539"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="468" height="60">
<param name=movie value="images/ti1.swf">
<param name=quality value=high>
<param name="wmode" value="transparent">
<embed src="/blog_article/images/ti1.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60" wmode="transparent">
</embed>
</object> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td background="images/211.gif" height="2"> </td>
</tr>
</table>
<table><FORM name=form1 action=search.php method=post target=_blank>
<table width="80%" border="0" cellspacing="0" cellpadding="0" bgcolor="#009933" align="center">
<tr>
<td align="center">
<input type="text" name="key">
<select name="type">
<option value=>全部类别</option>
<? $typ=file("list.txt");
$num=count($typ);
for($i=2;$i<=$num;$i++)
{
echo"<option value=$typ[$i]>$typ[$i]</option>";}
?>
</select>
<select name="whe">
<option value=>全部内容</option>
<option value=1>文章内容</option>
<option value=2>文章标题</option>
<option value=3>加入时间</option>
</select>
<input type="hidden" name="submit" value="1">
<input type="submit" name="submit" value="提交查询">
</td>
</tr>
</table>
</FORM></table>
<?
$type=trim($type);
if($comm)
{
$sec="and comm=1";
$fir="where comm=1";
}
if(!empty($type))
$query="select count(*) from $table where type='$type' $sec";
else
$query="select count(*) from $table $fir";
$res=mysql_db_query("$database",$query);
if(@mysql_num_rows($res)>0)
$tot=mysql_fetch_array($res);
$total=$tot[0];
$total_page=ceil($total/$pagenum);
echo "<table width="80%" border="0" cellspacing="0" cellpadding="0" align=center>";
echo "<tr><td>共:".$total."篇".$total_page."页</td></tr>";
if(empty($page))
$page=0;
if(empty($offset))
$offset=0;
$offset=$pagenum*$page;
if(!empty($type))
$query="select * from $table where type='$type' $sec order by id desc limit $offset,$pagenum";
else
$query="select * from $table $fir order by id desc limit $offset,$pagenum";
$res=mysql_db_query("$database",$query);
if(@mysql_num_rows($res)>0)
while($topic=mysql_fetch_array($res))
{
if(strlen($topic[title])>40)
{
$topic[title]=substr($topic[title],0,40) ;
$topic[title]=$topic[title].".....";
}
if(trim($topic[time])==date(Y年m月d日))
$topic[time]="<font color=#FF9900>$topic[time]</font>";
echo" <tr><td>[$topic[type]]<a href=# onClick="opwin($topic[id])";>$topic[title]</a><font size=1>($topic[time])</font>";
if($topic[comm]==1)
echo "<img src="/blog_article/images/comm.gif" alt="精品文章">";
if($topic[locked]==1)
echo "<img src="/blog_article/images/locked.gif" alt="文章已锁定">";
echo "</td>
<td>阅读:$topic[hits] 次;评论:$topic[p_num]次</td>
</tr>";
}
else
echo " 对不起,本栏 目暂没有任何文章!!!";
echo "</table>";
?>
<br>
<table width="80%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<?
$pre=$page-1;
$next=$page+1;
if($page>0)
echo "<a href="/blog_article/$php_self/page/$pre/amp;type/$type.html">上一页</a><br><br>";
else
echo "上一页<br><br>"; ?></td>
<td><?if($page<$total_page-1)
echo " <a href="/blog_article/$php_self/page/$next/amp;type/$type.html">下一页</a><br><br>";
else echo " 下一页<br><br>";?></td>
<td>
<form> 跳转到:
<select name="page" onchange="top.location='<? echo $php_self;?>?page='+document.forms[1].elements[0].value+'&type=<?echo $type;?>';" >
<?
for($i=0;$i<$total_page;$i++)
{
$p=$i+1;
echo "<option value=$i";
if($page==$i) echo " selected" ;
echo ">第".$p."页</option>n";
}
?>
</select> </form>
</td>
<td>
<form >选择栏目:
<select name="type" onchange="top.location='<? echo $php_self;?>?type='+document.forms[2].elements[0].value<?if($comm) echo"+'&comm=1'";?>;" >
<? $typ=file("list.txt");
$num=count($typ);
for($i=0;$i<$num;$i++)
{
echo"<option value=$typ[$i] "; if(trim($typ[$i])==$type) { echo " selected"; } echo ">$typ[$i]</option>";}
?>
</select>
</form>
</td><td><form method="post" action=<? echo $PHP_SELF;?>?type=<?echo $type;?> target="_balnk"><input type="submit" name="comm" value="精品文章" ./inc/footer.inc";?>
#####################read_article.php#########################
<?
require"./inc/func.php";
if(!$id)
{
echo"<script>window.close();</script>";
exit();
}
mscon();
$query="select * from $table where id='$id'";
$res=mysql_db_query("$database",$query);
if(!$res)
{
echo "this article has been deleted or no this article!!";
exit();
}
$data=mysql_fetch_array($res);
add_hits($data[id]);
$pre=$data[id]-1;
$next=$data[id]+1;
?>
<HTML>
<HEAD>
<TITLE>
<? echo "$data[title]--[$data[type]]";?>
</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<style type=text/css>
<!--
body,table,td,input,textarea { font-family: "宋体"; font-size: 9pt}
select { font-family: "宋体"; font-size: 9pt}
code {font-family: "Courier" ; font-size: 10pt}
a { color: #005500}
a:hover { color: #CC0000}
.border {border: 1px #000000 solid; background-color:transparent; list-style-position: inside; list-style-type: square}
-->
</style>
<script language="javascript">
function name()
{
var theResult = true;
var elem4 = null;
if (document.forms[0].elements[0].value == "" || document.forms[0].elements[0].value == "undefined" || document.forms[0].elements[0].value == "null")
{
elem4 = prompt("请输入您的姓名:","");
theResult = false;
document.forms[0].elements[0].value = elem4;
}
return theResult;
}
function mail()
{
var theResult = true;
var elem1 = null
if ((document.forms[0].elements[1].value.indexOf('@') == -1 || document.forms[0].elements[1].value == "" || document.forms[0].elements[1].value.indexOf('.') == -1))
{
elem1 = prompt("请输入您的正确的电子邮件地址。谢谢!!","");
theResult = false;
document.forms[0].elements[1].value = elem1;
}
return theResult;
}
function go()
{
var theResult=true;
theResult = name()&&mail();
return theResult;
}
</script>
</HEAD>
<BODY text=#000000 bgColor=#ffffff>
<TABLE borderColor=#339933 cellSpacing=0 borderColorDark=#ffffff
cellPadding=0 align=center borderColorLight=#000000 border=1 width=545>
<TBODY>
<TR vAlign=center bgColor=#009900>
<TD background=images/third-back3.gif>
<TABLE cellSpacing=0 cellPadding=0 width=100% border=0>
<TBODY>
<TR>
<TD width=17> </TD>
<TD width=590>
<TABLE width="36%" align=center border=0>
<TBODY>
<TR>
<TD bgcolor="#009900">
<DIV align=center><FONT face="Verdana, Arial, Helvetica, sans-serif" color=#ffffff><b>
<? echo $data[title];?>
</b></FONT></DIV>
</TD></TR></TBODY></TABLE></TD>
<TD width=19>
<DIV align=center><A href="javascript:window.close()"><IMG height=17
src="/blog_article/images/third-close.gif" width=17 align=absMiddle
border=0 name=content_r03_c28></A></DIV>
</TD></TR></TBODY></TABLE></TD></TR>
<TR vAlign=center align=left bgColor=#cccccc>
<TD>
<TABLE cellSpacing=0 cellPadding=0 border=0 align="center" width="100%">
<TBODY>
<TR>
<TD>
<DIV align=left><A read_article.php?id=<? echo $pre;?>"><img src="/blog_article/images/prethread.gif" width="48" height="12" border="0"></A></DIV>
</TD>
<TD>
<DIV align=left><a read_article.php?id=<? echo $next;?>"><img src="/blog_article/images/nextthread.gif" width="48" height="12" border="0"></a></DIV>
</TD>
<TD><IMG
height=16 src="/blog_article/images/mail.gif" width=16></TD>
<TD commend.php?id=<? echo "$data[id]&title=$data[title]";?>">推荐给朋友</A></TD>
<TD> 发表时间:
<? echo $data[time];?>
阅读次数:
<? echo $data[hits];?>
</TD>
<TD> </TD>
</TR>
</TBODY>
</TABLE>
</TD></TR>
<TR vAlign=top>
<TD <img src=/blog_article/images/lock.gif";
}
else
if($data[html]==1)
highlight_string($data[cont]);
else
echo nl2br($data[cont]);
?>
</TD>
</TR>
</TBODY></TABLE>
<table bordercolor=#339933 cellspacing=0 bordercolordark=#ffffff
cellpadding=0 align=center bordercolorlight=#000000 border=1 width=545>
<tbody>
<TR bgColor=#cccccc>
<th>
<DIV align=center>发表评论</DIV>
</th>
</TR>
<tr>
<td>
<form name="form1" method="post" action="/blog_article/ping.html" onsubmit="return go()">
您的姓名:
<input type="text" name="name" >
您的电子邮件:
<input type="text" name="mail" size=20 >
仅站长可见:<input type="checkbox" name="pub" value="<? echo $data[title];?>">
<input type="hidden" name="p_id" value="<? echo $id;?>">
<br>
发表评论:
<textarea name="cont" rows="8" cols="85"></textarea>
<br>
<br>
<center>
<input type="submit" name="Submit" value="提交" >
<input type="reset" name="Submit2" value="重写" >
</center></form>
</td>
</tr>
<TR bgColor=#cccccc>
<th>
<DIV align=center>相关评论</DIV>
</th>
</TR>
<tr>
<td>
<? $query="select * from $ping_tab where p_id='$id' order by time desc";
$res=mysql_db_query("$database",$query);
if(mysql_num_rows($res)>0)
{$i=1;
while($ping=mysql_fetch_array($res))
echo "评论人:$ping[name] 电子邮件:$ping[mail]<br> ".nl2br($ping[p_cont])."<br>时间:$ping[time] 来自:$ping[ip]<hr size=1>n" ;
}
else
echo "暂时没有本文章的相关评论!";
?>
</td>
</tr>
<tr bgcolor=#cccccc>
<td>
<div align=center><a
href="javascript:window.close()">关闭窗口</a></div>
</td>
</tr>
</tbody>
</table>
<?require "./inc/footer.inc";?>
<?session_start();
require"./inc/func.php";
mscon();
require "./inc/header.inc";
?>
<script language="javascript">
function opwin(filename)
{ window.open("read_article.php?id="+filename,"","height=500,width=585,resizable=no,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#003399" height="23">
<tr>
<td width="80">
<div id="Layer2" ><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="80" height="60">
<param name=movie value="images/logo.swf">
<param name=quality value=high>
<param name="wmode" value="transparent">
<embed src="/blog_article/images/logo.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="80" height="60" wmode="transparent">
</embed>
</object></div>
<div id="Layer1" ><img src="/blog_article/images/11.gif" width="58" height="55"></div>
</td>
<td width="539"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="468" height="60">
<param name=movie value="images/ti1.swf">
<param name=quality value=high>
<param name="wmode" value="transparent">
<embed src="/blog_article/images/ti1.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60" wmode="transparent">
</embed>
</object> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td background="images/211.gif" height="2"> </td>
</tr>
</table>
<table><FORM name=form1 action=search.php method=post target=_blank>
<table width="80%" border="0" cellspacing="0" cellpadding="0" bgcolor="#009933" align="center">
<tr>
<td align="center">
<input type="text" name="key">
<select name="type">
<option value=>全部类别</option>
<? $typ=file("list.txt");
$num=count($typ);
for($i=2;$i<=$num;$i++)
{
echo"<option value=$typ[$i]>$typ[$i]</option>";}
?>
</select>
<select name="whe">
<option value=>全部内容</option>
<option value=1>文章内容</option>
<option value=2>文章标题</option>
<option value=3>加入时间</option>
</select>
<input type="hidden" name="submit" value="1">
<input type="submit" name="submit" value="提交查询">
</td>
</tr>
</table>
</FORM></table>
<?
$type=trim($type);
if($comm)
{
$sec="and comm=1";
$fir="where comm=1";
}
if(!empty($type))
$query="select count(*) from $table where type='$type' $sec";
else
$query="select count(*) from $table $fir";
$res=mysql_db_query("$database",$query);
if(@mysql_num_rows($res)>0)
$tot=mysql_fetch_array($res);
$total=$tot[0];
$total_page=ceil($total/$pagenum);
echo "<table width="80%" border="0" cellspacing="0" cellpadding="0" align=center>";
echo "<tr><td>共:".$total."篇".$total_page."页</td></tr>";
if(empty($page))
$page=0;
if(empty($offset))
$offset=0;
$offset=$pagenum*$page;
if(!empty($type))
$query="select * from $table where type='$type' $sec order by id desc limit $offset,$pagenum";
else
$query="select * from $table $fir order by id desc limit $offset,$pagenum";
$res=mysql_db_query("$database",$query);
if(@mysql_num_rows($res)>0)
while($topic=mysql_fetch_array($res))
{
if(strlen($topic[title])>40)
{
$topic[title]=substr($topic[title],0,40) ;
$topic[title]=$topic[title].".....";
}
if(trim($topic[time])==date(Y年m月d日))
$topic[time]="<font color=#FF9900>$topic[time]</font>";
echo" <tr><td>[$topic[type]]<a href=# onClick="opwin($topic[id])";>$topic[title]</a><font size=1>($topic[time])</font>";
if($topic[comm]==1)
echo "<img src="/blog_article/images/comm.gif" alt="精品文章">";
if($topic[locked]==1)
echo "<img src="/blog_article/images/locked.gif" alt="文章已锁定">";
echo "</td>
<td>阅读:$topic[hits] 次;评论:$topic[p_num]次</td>
</tr>";
}
else
echo " 对不起,本栏 目暂没有任何文章!!!";
echo "</table>";
?>
<br>
<table width="80%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<?
$pre=$page-1;
$next=$page+1;
if($page>0)
echo "<a href="/blog_article/$php_self/page/$pre/amp;type/$type.html">上一页</a><br><br>";
else
echo "上一页<br><br>"; ?></td>
<td><?if($page<$total_page-1)
echo " <a href="/blog_article/$php_self/page/$next/amp;type/$type.html">下一页</a><br><br>";
else echo " 下一页<br><br>";?></td>
<td>
<form> 跳转到:
<select name="page" onchange="top.location='<? echo $php_self;?>?page='+document.forms[1].elements[0].value+'&type=<?echo $type;?>';" >
<?
for($i=0;$i<$total_page;$i++)
{
$p=$i+1;
echo "<option value=$i";
if($page==$i) echo " selected" ;
echo ">第".$p."页</option>n";
}
?>
</select> </form>
</td>
<td>
<form >选择栏目:
<select name="type" onchange="top.location='<? echo $php_self;?>?type='+document.forms[2].elements[0].value<?if($comm) echo"+'&comm=1'";?>;" >
<? $typ=file("list.txt");
$num=count($typ);
for($i=0;$i<$num;$i++)
{
echo"<option value=$typ[$i] "; if(trim($typ[$i])==$type) { echo " selected"; } echo ">$typ[$i]</option>";}
?>
</select>
</form>
</td><td><form method="post" action=<? echo $PHP_SELF;?>?type=<?echo $type;?> target="_balnk"><input type="submit" name="comm" value="精品文章" ./inc/footer.inc";?>
#####################read_article.php#########################
<?
require"./inc/func.php";
if(!$id)
{
echo"<script>window.close();</script>";
exit();
}
mscon();
$query="select * from $table where id='$id'";
$res=mysql_db_query("$database",$query);
if(!$res)
{
echo "this article has been deleted or no this article!!";
exit();
}
$data=mysql_fetch_array($res);
add_hits($data[id]);
$pre=$data[id]-1;
$next=$data[id]+1;
?>
<HTML>
<HEAD>
<TITLE>
<? echo "$data[title]--[$data[type]]";?>
</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<style type=text/css>
<!--
body,table,td,input,textarea { font-family: "宋体"; font-size: 9pt}
select { font-family: "宋体"; font-size: 9pt}
code {font-family: "Courier" ; font-size: 10pt}
a { color: #005500}
a:hover { color: #CC0000}
.border {border: 1px #000000 solid; background-color:transparent; list-style-position: inside; list-style-type: square}
-->
</style>
<script language="javascript">
function name()
{
var theResult = true;
var elem4 = null;
if (document.forms[0].elements[0].value == "" || document.forms[0].elements[0].value == "undefined" || document.forms[0].elements[0].value == "null")
{
elem4 = prompt("请输入您的姓名:","");
theResult = false;
document.forms[0].elements[0].value = elem4;
}
return theResult;
}
function mail()
{
var theResult = true;
var elem1 = null
if ((document.forms[0].elements[1].value.indexOf('@') == -1 || document.forms[0].elements[1].value == "" || document.forms[0].elements[1].value.indexOf('.') == -1))
{
elem1 = prompt("请输入您的正确的电子邮件地址。谢谢!!","");
theResult = false;
document.forms[0].elements[1].value = elem1;
}
return theResult;
}
function go()
{
var theResult=true;
theResult = name()&&mail();
return theResult;
}
</script>
</HEAD>
<BODY text=#000000 bgColor=#ffffff>
<TABLE borderColor=#339933 cellSpacing=0 borderColorDark=#ffffff
cellPadding=0 align=center borderColorLight=#000000 border=1 width=545>
<TBODY>
<TR vAlign=center bgColor=#009900>
<TD background=images/third-back3.gif>
<TABLE cellSpacing=0 cellPadding=0 width=100% border=0>
<TBODY>
<TR>
<TD width=17> </TD>
<TD width=590>
<TABLE width="36%" align=center border=0>
<TBODY>
<TR>
<TD bgcolor="#009900">
<DIV align=center><FONT face="Verdana, Arial, Helvetica, sans-serif" color=#ffffff><b>
<? echo $data[title];?>
</b></FONT></DIV>
</TD></TR></TBODY></TABLE></TD>
<TD width=19>
<DIV align=center><A href="javascript:window.close()"><IMG height=17
src="/blog_article/images/third-close.gif" width=17 align=absMiddle
border=0 name=content_r03_c28></A></DIV>
</TD></TR></TBODY></TABLE></TD></TR>
<TR vAlign=center align=left bgColor=#cccccc>
<TD>
<TABLE cellSpacing=0 cellPadding=0 border=0 align="center" width="100%">
<TBODY>
<TR>
<TD>
<DIV align=left><A read_article.php?id=<? echo $pre;?>"><img src="/blog_article/images/prethread.gif" width="48" height="12" border="0"></A></DIV>
</TD>
<TD>
<DIV align=left><a read_article.php?id=<? echo $next;?>"><img src="/blog_article/images/nextthread.gif" width="48" height="12" border="0"></a></DIV>
</TD>
<TD><IMG
height=16 src="/blog_article/images/mail.gif" width=16></TD>
<TD commend.php?id=<? echo "$data[id]&title=$data[title]";?>">推荐给朋友</A></TD>
<TD> 发表时间:
<? echo $data[time];?>
阅读次数:
<? echo $data[hits];?>
</TD>
<TD> </TD>
</TR>
</TBODY>
</TABLE>
</TD></TR>
<TR vAlign=top>
<TD <img src=/blog_article/images/lock.gif";
}
else
if($data[html]==1)
highlight_string($data[cont]);
else
echo nl2br($data[cont]);
?>
</TD>
</TR>
</TBODY></TABLE>
<table bordercolor=#339933 cellspacing=0 bordercolordark=#ffffff
cellpadding=0 align=center bordercolorlight=#000000 border=1 width=545>
<tbody>
<TR bgColor=#cccccc>
<th>
<DIV align=center>发表评论</DIV>
</th>
</TR>
<tr>
<td>
<form name="form1" method="post" action="/blog_article/ping.html" onsubmit="return go()">
您的姓名:
<input type="text" name="name" >
您的电子邮件:
<input type="text" name="mail" size=20 >
仅站长可见:<input type="checkbox" name="pub" value="<? echo $data[title];?>">
<input type="hidden" name="p_id" value="<? echo $id;?>">
<br>
发表评论:
<textarea name="cont" rows="8" cols="85"></textarea>
<br>
<br>
<center>
<input type="submit" name="Submit" value="提交" >
<input type="reset" name="Submit2" value="重写" >
</center></form>
</td>
</tr>
<TR bgColor=#cccccc>
<th>
<DIV align=center>相关评论</DIV>
</th>
</TR>
<tr>
<td>
<? $query="select * from $ping_tab where p_id='$id' order by time desc";
$res=mysql_db_query("$database",$query);
if(mysql_num_rows($res)>0)
{$i=1;
while($ping=mysql_fetch_array($res))
echo "评论人:$ping[name] 电子邮件:$ping[mail]<br> ".nl2br($ping[p_cont])."<br>时间:$ping[time] 来自:$ping[ip]<hr size=1>n" ;
}
else
echo "暂时没有本文章的相关评论!";
?>
</td>
</tr>
<tr bgcolor=#cccccc>
<td>
<div align=center><a
href="javascript:window.close()">关闭窗口</a></div>
</td>
</tr>
</tbody>
</table>
<?require "./inc/footer.inc";?>
[3]使用sockets:从新闻组中获取文章(二)
来源: 互联网 发布时间: 2013-11-30
与服务器对话
现在我们已经连接到了服务器,可以通过前面打开的socket同服务器对话了。比如说我们要从某个新闻组得到最近的10篇文章。RFC977指出,第一步要用GROUP命令选择正确的新闻组:
GROUP ggg
参数ggg是要选择的新闻组的名字(比如说是"net.news"),这是必需的。可用的新闻组的列表可以用LIST命令得到。选择新闻组的命令成功后,返回组中第一篇和最后一篇文章的文章编号,以及组中文章的数目。
下面是一个例子:
chrome:~$ telnet my.news.host 119
Trying aa.bb.cc.dd...
Connected to my.news.host.
Escape character is '^]'.
200 my.news.host InterNetNews NNRP server INN 2.2.2 13-Dec-1999 ready (posting ok).
GROUP alt.test
211 232 222996 223235 alt.test
quit
205 .
接收到命令 GROUP alt.test 后,服务器返回"211 232 222996 223235 alt.test". 211是RFC中定义的返回码,指示命令已成功执行。返回信息还指出,现在有232篇文章,最早的文章的编号是222996,最新的文章的编号是223235。我们看到,222996+232并不等于223235。丢失的7篇文章因为某种原因被从服务器删除了,可能是因为被它的合法作者取消了(这是可能的,而且很容易做到),或者因为是灌水文章而被删。
需要注意的事,有些服务器在选择新闻组之前可能要求身份认证,这取决于这是一个公共的或者是私用的服务器。也有可能服务器允许任何人读取文章,但发表文章需要身份验证。
<?php
//$cfgUser = "xxxxxx";
//$cfgPasswd = "yyyyyy";
$cfgNewsGroup = "alt.php";
//identification required on private server
if($cfgUser) {
fputs($usenet_handle, "AUTHINFO USER ".$cfgUser."n");
$tmp = fgets($usenet_handle, 1024);
fputs($usenet_handle, "AUTHINFO PASS ".$cfgPasswd."n");
$tmp = fgets($usenet_handle, 1024);
//check error
if($tmp != "281 Okrn") {
echo "502 Authentication errorn";
exit();
}
}
//select newsgroup
fput($usenet_handle, "GROUP ".$cfgNewsGroup."n");
$tmp = fgets($usenet_handle, 1024);
if($tmp == "480 Authentication required for commandrn") {
echo $tmp;
exit();
}
$info = split(" ", $tmp);
$first= $info[2];
$last = $info[3];
printf("First : %sn", $first);
printf("Last : %lastn", $last);
?>
现在我们已经连接到了服务器,可以通过前面打开的socket同服务器对话了。比如说我们要从某个新闻组得到最近的10篇文章。RFC977指出,第一步要用GROUP命令选择正确的新闻组:
GROUP ggg
参数ggg是要选择的新闻组的名字(比如说是"net.news"),这是必需的。可用的新闻组的列表可以用LIST命令得到。选择新闻组的命令成功后,返回组中第一篇和最后一篇文章的文章编号,以及组中文章的数目。
下面是一个例子:
chrome:~$ telnet my.news.host 119
Trying aa.bb.cc.dd...
Connected to my.news.host.
Escape character is '^]'.
200 my.news.host InterNetNews NNRP server INN 2.2.2 13-Dec-1999 ready (posting ok).
GROUP alt.test
211 232 222996 223235 alt.test
quit
205 .
接收到命令 GROUP alt.test 后,服务器返回"211 232 222996 223235 alt.test". 211是RFC中定义的返回码,指示命令已成功执行。返回信息还指出,现在有232篇文章,最早的文章的编号是222996,最新的文章的编号是223235。我们看到,222996+232并不等于223235。丢失的7篇文章因为某种原因被从服务器删除了,可能是因为被它的合法作者取消了(这是可能的,而且很容易做到),或者因为是灌水文章而被删。
需要注意的事,有些服务器在选择新闻组之前可能要求身份认证,这取决于这是一个公共的或者是私用的服务器。也有可能服务器允许任何人读取文章,但发表文章需要身份验证。
<?php
//$cfgUser = "xxxxxx";
//$cfgPasswd = "yyyyyy";
$cfgNewsGroup = "alt.php";
//identification required on private server
if($cfgUser) {
fputs($usenet_handle, "AUTHINFO USER ".$cfgUser."n");
$tmp = fgets($usenet_handle, 1024);
fputs($usenet_handle, "AUTHINFO PASS ".$cfgPasswd."n");
$tmp = fgets($usenet_handle, 1024);
//check error
if($tmp != "281 Okrn") {
echo "502 Authentication errorn";
exit();
}
}
//select newsgroup
fput($usenet_handle, "GROUP ".$cfgNewsGroup."n");
$tmp = fgets($usenet_handle, 1024);
if($tmp == "480 Authentication required for commandrn") {
echo $tmp;
exit();
}
$info = split(" ", $tmp);
$first= $info[2];
$last = $info[3];
printf("First : %sn", $first);
printf("Last : %lastn", $last);
?>
最新技术文章: