Subject: php script problems!
I'm planning on making a bot thats going to respond to what people asks it. Like -
Someone says hello. It says hey back.
Someone asks What are you doing? It says im not doing much. I'm
just an robot.
And so on..
<?php
If "Hello";
echo "Hey";
break;
If "what are you
doing?"
echo "Not doing much, I'm just an robot."
?>
Is this anything near what im looking for? Could you just make one sample of what im asking for? Then i would understand it.
Comments are currently closed for this discussion. You can start a new one.
2 Posted by Acorn on 31 Jan, 2010 11:22 PM
<?php
If ($REQUEST['msg'] = "Hello") {
echo "Hey";
}; If ($REQUEST['msg'] = "what are you doing?") {
echo "Not doing much, I'm just an robot.";
}; ?>
Not the best way to go about it though.
Support Staff 3 Posted by Adam Kalsey on 31 Jan, 2010 11:51 PM
You'll want to use == instead of = in your if statements. In PHP, =
is an assignment operator (so you're setting the value of
$_REQUEST['msg'] to "Hello") and == is a comparison operator (checking
to see of the two things are equal.
You also don't use a semicolon after the closing } in the if statement.
You're correct, however, that you'll be fairly limited with this
direct comparison approach. If I don't ask the bot exactly "what are
you doing?" then it won't respond. If I said "what are you doing"
without the question mark, then there's no match and not response.
Your best bet for getting a natural language chatbot up and running
without having to write all the fuzzy matching logic yourself would be
to use an A.L.I.C.E. or Eliza bot as the back end. ALICE and Eliza are
an artificial intelligence engines for writing conversational robots.
There's some sample code for integrating a simple open source ALICE
engine with IMified at
http://help.imified.com/discussions/questions/601-imified-bot-with-alice
4 Posted by Acorn on 01 Feb, 2010 12:00 AM
Oops, sorry, just a beginner when it comes to PHP. Thanks for the corrections.
5 Posted by Markus Løyte on 01 Feb, 2010 12:09 AM
I did not understand a thing of that alice bot thing.. Is there any way you can tell me how to use and set it up in a beginner friendly way?
6 Posted by Markus Løyte on 01 Feb, 2010 06:04 PM
I'm gonna make the bot the same way as Acorn wrote the script, but the script is not working.. Can someone just write an pretty basic script that does respond to hello, hey and whats up?
The script Acorn made did not work. I just said efded to it and it sent me everything in one sentence..
Thanks!
Markus
7 Posted by Acorn on 01 Feb, 2010 06:31 PM
<?php
If ($REQUEST['msg'] == "Hello") {
echo "Hey";
} If ($REQUEST['msg'] == "what are you doing?") {
echo "Not doing much, I'm just an robot.";
} ?>
That should respond if you send exactly "Hello" or "what are you doing?" to the bot
A better way would be with the switch operator:
<?php
switch ($REQUEST['msg'] ) {
case "Hello":
echo "Hey";
break;
case "How are you?":
echo "fine";
break;
} ?>
Neither of these ways are good though.
8 Posted by Markus Løyte on 01 Feb, 2010 09:09 PM
I tried both of the phps, but the bot ain't responding! I say "Hello" without the "'s.
nothing happens. I did even try to restart the bot..
Support Staff 9 Posted by Adam Kalsey on 03 Feb, 2010 05:30 PM
The correct variable for accessing the request array in PHP is
$_REQUEST and not $REQUEST. So you'd use $_REQUEST['msg']
It is also recommended to explicitly use $_POST or $_GET instead of
$_REQUEST as accepting GET requests on things that you're expecting
the user to submit a form post on can lead to Cross Site Request
Forgery (CSRF) attacks. See
http://shiflett.org/articles/cross-site-request-forgeries for a full
explanation of the issue.
What you'd really want to do is use $_POST['msg'] instead.