Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Using sockets in PHP : Get articles from Usenet
Talking to the Server
We are now connected to the server, and can talk to it through th previously opened socket. Let us say we want to get the 10 latest articles from some newsgroup. RFC977 specifies that the first step is to select the right newsgroup with the GROUP command :
GROUP ggg
The required parameter ggg is the name of the newsgroup to be selected (e.g. "net.news"). A list of valid newsgroups may be obtained from the LIST command. The successful selection response will return the article numbers of the first and last articles in the group, and an estimate of the number of articles on file in the group.
Example:
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 .
After receiving the command " GROUP alt.test", the News Server answered "211 232 222996 223235 alt.test". 211 is an RFC defined code (basically saying the command was succesfully executed - check the RFC for more details). It also answered it currently has 232 articles, indexed 222996 for the oldest through 223235 for the latest. These are called article numbers. Now, let us have a count here : 222996 + 232 by no means equals to 232235. The seven missing articles were removed one way or another from the server, either cancelled by their legitimate author (yes, it is possible and easy to do !) or deleted after report of abuse for example.
Be careful though, the server might require authentication before selecting the newsgroup, depending on wether it is a public or private server. It could also let anybody retrieve articles but require authentication to publish an article.

<?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 Ok\r\n") {
        echo
"502 Authentication error\n";
        exit();
    }    
}

// select newsgroup

fputs($usenet_handle, "GROUP ".$cfgNewsGroup."\n");
$tmp = fgets($usenet_handle, 1024);

if(
$tmp == "480 Authentication required for command\r\n") {
    echo
"$tmp\n";
    exit();
}    

$info = split(" ", $tmp);
$first = $info[2];
$last = $info[3];

print
"First : $first\n";
print
"Last : $last\n";


?>
[ Next Page ]

[Page 1]  [Page 2]  


Comments:
RE: Sockets and Half-LifeJustin Frydman02/14/06 01:56
RE: use php exec() to Control Parallel Port coolvista10/31/05 13:24
RE: Retrieving article from usenetsangeeta chakraborty10/15/05 00:24
saving scriptsRogy04/05/05 08:15
how to access external email behind my proxyrelly02/15/05 20:53
RE: Sockets and Half-LifeTurk01/25/05 13:38
And how about those fairies? Sex12/05/04 04:48
For some reason, Sex12/05/04 04:47
PLease, how Can i download. Sex Beplaced Ru 12/05/04 04:43
ummmmmmmmm whats this mummy??Sex Beplaced Ru 12/05/04 04:34
This was closely associated with the rebirth of Freeflashonlinegames Com 12/05/04 04:33
Thanks. I hope other people test it too. Freeflashonlinegames Com 12/05/04 04:33
This was closely associated with the rebirth of Sex Beplaced Ru 12/05/04 04:32
die Reet is anders een gemene man...Freeflashonlinegames Com 12/05/04 04:31
You are right ofcourse... But...Sex Beplaced Ru 12/05/04 04:31
For some reason, Sex Beplaced Ru 12/05/04 04:29
Were there ever real witches? Sex12/05/04 04:28
This was closely associated with the rebirth of Sex12/05/04 04:26
What?, don't they know who we are? Freeflashonlinegames Com 12/05/04 04:25
Finally figured this out - my Sex12/05/04 04:25
If not, what were all the witch trials about? Sex12/05/04 04:23
PLease, how Can i download. Freeflashonlinegames Com 12/05/04 04:08
RE: HTTP Proxy Servers and PHP SocketsRev Aaron04/23/04 10:47
RE: Quake III ProtocolKyle04/02/04 13:42
RE: Sockets not working...Please helpusman shahid10/19/02 04:58
Retrieving ip from urlSmoske09/20/02 15:19
Sockets not working...Please helpRenny09/19/02 14:03
Sned HTML message to all connected clientJim09/13/02 08:17
How to use PHP Control Paralle PortPyrawate09/09/02 00:32
How to use PHP Control Paralle PortPyrawate09/08/02 23:59
RE: Retrive client's ip addressQuan Mac09/04/02 00:54
RE: How to open sockets from behind proxy serverIonut Daia08/22/02 20:39
ADVANCED PHP SOCKETSGustavo Almeida08/14/02 14:34
ADVANCED PHP (SOCKET)Gustavo Almeida08/14/02 14:27
timeout does not workOsman Darcan08/06/02 19:32
RE: How to open sockets from behind proxy serverzingit07/18/02 04:53
StuckBamma06/29/02 17:57
RE: Sockets and Half-Life full script hereNvE0s06/26/02 19:41
passing parameterVit06/25/02 23:24
Quake III ProtocolJohan06/24/02 15:24
GET??Giuseppe06/20/02 05:22
Retrive client's ip addressJohn06/16/02 03:17
Script for negotiating proxy with user auth.Xixulon06/14/02 10:52
RE: How to open sockets from behind proxy serveXixulon06/14/02 10:49
Wap -> Website -> Computer shutdown.Marek Miettinen06/14/02 06:56
RE: IRC Socket?Bryan06/12/02 01:36
RE: Browser Chat clientMax Mo06/11/02 08:10
RE: PHP sockets/networksKamran05/07/02 03:49
RE: IRC Socket?rubbi05/03/02 13:05
RE: PHP sockets/networksMorrissey04/27/02 03:25
html codesmarie shelton04/22/02 07:23
ProxyTom04/15/02 08:59
RE: Re Sockets and Half-Lifebstanescu04/08/02 05:52
PERL Sockets AND PHP Socketspopnikos04/03/02 09:24
RE: Browser Chat clientbluBattery03/13/02 14:54
cookiesmohd03/09/02 16:37
Accessing POP3 mailbox using PHP SocketsArun G P Dutt03/07/02 00:41
RE: socket codeMichelle02/26/02 17:58
RE: Sockets and Half-LifeDave02/18/02 18:46
RE: Browser Chat clientRob_Earl02/05/02 22:14
RE: How to redirect in LANRob02/05/02 21:54
RE: importing a html page in a php scriptRob02/05/02 21:32
RE: How to redirect in LANRob02/05/02 21:30
RE: Sockets and Half-LifeRob02/05/02 15:46
RE: PHP telnet client?Per-Ingar Auberg02/02/02 06:03
Telnet scripting from PHPPer-Ingar Auberg02/02/02 06:00
RE: How to open sockets from behind proxy serverValberg Larusson01/19/02 01:02
socket codeColleen01/16/02 16:47
RE: How to post a form to another...Palan01/12/02 17:51
socket response-urg!!!sands01/09/02 10:50
How can I change xml file to php arrayS.Murali Krishna01/08/02 05:21
How to redirect in LANmk401/05/02 05:28
RE: Sockets and Half-LifeRuud Kamphuis01/01/02 09:05
RE: Sockets and Half-LifeDinesh12/30/01 14:46
RE: PHP telnet sockets(was client)Gulopine12/20/01 11:14
importing a html page in a php scriptjoe12/14/01 20:11
Retrieving article from usenetBill12/12/01 18:05
RE: How to open sockets from behind proxy serverSteven Chalker12/11/01 17:04
How to open sockets from behind proxy serverSatish Krishna12/04/01 06:43
Display pictures which are attached?valerie11/29/01 14:16
Can pictures be displaid which are attached? valerie11/28/01 18:41
opening sockets in phpYogesh Randhawa11/28/01 07:33
PHP sockets/networksArmando P.11/21/01 05:21
How can I catch a socket in action?Albert MAYE11/05/01 09:58
How to post a form to another...Marcel11/05/01 08:25
And now, what's is the final script?mc-no-solard11/04/01 12:41
Can I display pictures which are attached?Jens11/03/01 10:41
RE: saving php output in html fileTomas10/29/01 12:51
RE: how to enable socket() in PHParchi6910/21/01 23:59
RE: Sockets and Half-Lifehuib bakker10/07/01 07:46
saving php output in html fileandrea09/28/01 05:49
all about socketslavanya09/28/01 05:28
Browser Chat clientLeeWynn09/15/01 19:42
QuestionSteven C09/07/01 10:31
FTP connectionJ.Bijleveld09/04/01 08:00
RE: I would like to known more about php Ger van Vugt08/18/01 08:58
how to enable socket() in PHPDiou07/30/01 03:02
RE: Sockets and Half-Lifeady07/28/01 09:33
How to make only on queryClaude07/27/01 02:56
RE: HTTPS SocketsdRago07/25/01 04:39
RE: I would like to known more about php Phillip Oertel07/24/01 04:52
SOCKET PHOJose Luis Castro07/18/01 13:09
help me!!!ice_berg1607/18/01 04:58
RE: Sockets and Half-Lifepaul07/09/01 22:55
RE: PHP telnet sockets(was client)OmagaSohe07/09/01 05:46
RE: IRC Socket?Nilo07/02/01 11:41
RE: IRC Socket?zeke07/02/01 02:48
Page LinksRavinder singh06/29/01 02:44
RE: IRC Socket?Bertrand DUNOGIER06/26/01 04:12
Sounds with PHPCHATAlan06/25/01 12:53
I would like to known more about php Hugo Ivan06/18/01 10:31
is the socket() function available in windowsPaul Villavicencio06/13/01 07:57
RE: HTTPS SocketsUwi06/13/01 07:34
Which nntp server to use?Seb Delcampe06/07/01 10:59
PHP Sockets...Kyle Olsen06/06/01 14:41
RE: PHP telnet client?Kyle Olsen06/04/01 11:30
RE: HTTPS SocketsJordan05/25/01 09:58
replacing charactersMike05/22/01 01:57
Sockets and Half-LifeRafael Bastidas05/21/01 11:28
Example at phpindex.com/ngAlex05/21/01 08:17
Getting Headers OnlySean05/20/01 01:11
RE: HTTPS SocketsErwin05/16/01 10:00
HTTPS SocketsJon Thomas05/13/01 18:32
PHP telnet client?jchc05/12/01 23:50
RE: IRC Socket?steve05/11/01 16:03
RE: decoding attachmentsOnno Benschop05/08/01 19:23
Achive this from behind a proxy !Steve haemelinck05/06/01 06:19
RE: PHP Sockets on Windowsbmpc05/06/01 04:49
RE: Oy, why did the RFC specify numeric codes?Armel FAUVEAU05/03/01 09:45
RE: IRC Socket?Armel FAUVEAU05/03/01 09:42
RE: IRC Socket?Mathieu 'CaPS' Kooiman05/02/01 23:20
RE: Oy, why did the RFC specify numeric codes?Mathieu 'CaPS' Kooiman05/02/01 23:18
IRC Socket?Ninconvert05/02/01 17:33
RE: Oy, why did the RFC specify numeric codes?Armel FAUVEAU05/02/01 17:20
Radius check using PHP+socketsO. van Zandwijk05/02/01 15:07
Oy, why did the RFC specify numeric codes?Mathieu 'CaPS' Kooiman05/01/01 05:59
RE: disconneting ....Dave05/01/01 05:00
RE: IMAP functions?Dave05/01/01 04:59
decoding attachmentsChristian Lund04/30/01 14:02
RE: IMAP functions?Justin Plock04/30/01 11:08
PHP Sockets on WindowsC Clarke04/30/01 06:39
RE: IMAP functions?Armel FAUVEAU04/29/01 17:47
RE: IMAP functions?Xan Nick04/29/01 10:33
IMAP functions?Justin Plock04/28/01 01:24
disconneting ....E.Daspet04/28/01 00:49
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.

 

Columns / Articles | Tips / Quickies | News | News Linking and RSS Feeds | Shared Code Library
Mail Archives | Support / Discussion Forums | Get Started! Links | Contribute! | Docs