Jump to content

PHP I/O from IRC?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
op2rules

op2rules

    Newbie

  • Members
  • Pip
  • 5 posts
Hey guys, I have a php script that I wrote and it creates short url links. It does so quite nicely, and the page is all shiny with jQuery ajax and loads of functionality and everything is great. Now I'm just wondering, where would I go to start to be able to make the script take data from somewhere other than the input form? Lets say I write an irc script to create short urls from within the irc client? How would I make it so that a link and expiration data and shorturl tag (the 3 paramaters for the url) get sent to the php script, and make it listen for the php response?

Right now the script takes the data from the form, creates the short url link and puts the 3 paramaters (expiration date, short tag, and url) in a mysql table. Then with .htaccess when you go to op2rules.net/shorttag it does a regex to turn the tag at the end to a $_GET variable, and then replaces the header with the matching url from the mysql table.

So again, what I want to do is be able to access all of this functionality from a program or a script that would run within IRC.

Thanks a load!

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
You need to use PHP Sockets and the IRC protocol as documented in the RFC 1459.

#3
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
I believe there is a great irc class in the pear library.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
Unless you're all using a client compatible with custom scripting, you need to create a bot to handle the communication, here is an extensively simple example:
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, $ip, $port);
sleep(1);
socket_write($socket, "(user ident code here)");
while ($read = socket_read($socket, 2048)) {
    //do something with socket data
    socket_write($socket, "/msg $user " . shortenUrl($read)) . "\n";
}

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
op2rules

op2rules

    Newbie

  • Members
  • Pip
  • 5 posts
Nonono guys thats not what I meant I don't want PHP to be the one connecting to IRC. I solved the problem by making a new file with a similar copy to the script, except this one used $_GET for the variables and then the python irc bot uses urlopen(sendurl).read() with the urlopen import from urllib to use the url to do what I want it to. That is assigned to a variable and the php echo output is then displayed on IRC.

Thanks anyways though!