VoiceXML Forum Community Message Board


Post New Topic  Post A Reply
my profile | register | search | faq | forum home
  next oldest topic   next newest topic
» VoiceXML Forum Community Message Board   » Newbies   » I need receive variables from a file.php

 - UBBFriend: Email this page to someone!    
Author Topic: I need receive variables from a file.php
Asier
Junior Member
Member # 3259

Icon 1 posted November 04, 2005 04:39 AM      Profile for Asier   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
Hello there,

I need receive seme variables from a php document, and i dont know how do it, please put me some code sample.

I thing is possible whit submit, subdailog, <tag> but my problem is how receive de varaibles, because i know send all variables to another document, and know how to work this tags more or less.

Thanks in advance

Posts: 7 | Registered: Sep 2005  |  IP: Logged
mikoun
Junior Member
Member # 3294

Rate Member
Icon 1 posted November 13, 2005 07:35 PM      Profile for mikoun   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
You can capture any POST/GET variables from PHP to VoiceXML. For example:

<!-- form document -->
......
<submit next="submit.php" namelist="varA varB" />
......

<!-- document submit.php -->
......
<assign name="varA" expr="'<? echo $varA; ?>'"/>
<assign name="varB" expr="'<? echo $varB; ?>'"/>

Mike,
VoiceXML Connect www.voicexmlconnect.com

--------------------
Integrated VoiceWeb Solutions
Affordable VoiceXML Hosting


Posts: 7 | From: Canada | Registered: Nov 2005  |  IP: Logged
Asier
Junior Member
Member # 3259

Icon 1 posted November 15, 2005 06:12 AM      Profile for Asier   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
Sorry, but this way is for send variables to php file, but i want receive variables from php file, thanks, is possible that i have mistake, thanks.
Posts: 7 | Registered: Sep 2005  |  IP: Logged
spkydog
Member
Member # 2785

Member Rated:
5
Icon 1 posted November 15, 2005 02:48 PM      Profile for spkydog   Author's Homepage   Email spkydog   Send New Private Message       Edit/Delete Post   Reply With Quote 
Mike's example shows how to submit variables from the VoiceXML document and how to retrieve those values in a server side PHP script.

What exactly do you mean by "receive variables from php file"?

--------------------
http://spkydog.blogspot.com

Posts: 75 | Registered: May 2004  |  IP: Logged
mheadd
Member
Member # 3181

Member Rated:
4
Icon 1 posted November 15, 2005 08:16 PM      Profile for mheadd   Author's Homepage   Email mheadd   Send New Private Message       Edit/Delete Post   Reply With Quote 
You can process variables submitted by a VoiceXML dialog to a PHP script by using one the superglobal arrays in PHP ($_GET, $_POST or $_REQUEST). Using the example above, if your VoiceXML dialog includes a submit statement with variables to be processed by a PHP script:
code:
  
<submit next="submit.php" namelist="varA varB"/>

Your PHP file (in this case, a script named "submit.php") would contain variable declarations as follows:
code:
  
$a = $_REQUEST['varA'];
$b = $_REQUEST['varB'];

Now you can do things with these variables:
code:
if (strlen($a) != 10 || strlen($b) != 9) {
echo 'An error has occurred';
}
else {
echo 'Everything is OK';
}

You can read more about submitting variables to PHP scripts on the PHP web site . Hope this is helpful.

--------------------
Mark
VoiceinGov.org
http://www.voiceingov.org

Posts: 55 | Registered: Jun 2005  |  IP: Logged
MrBaseball34
Junior Member
Member # 3303

Rate Member
Icon 1 posted November 18, 2005 04:51 PM      Profile for MrBaseball34     Send New Private Message       Edit/Delete Post   Reply With Quote 
You have to return the info FROM the PHP script
either as XML or VXML, then, if it is returned as
XML, parse it using ECMAScript. If the data is
returned as VXML, then you will be able to use
the variables just like any other in your app.

I will posst a sample later.

Posts: 5 | Registered: Nov 2005  |  IP: Logged
Asier
Junior Member
Member # 3259

Icon 1 posted November 22, 2005 04:54 AM      Profile for Asier   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
Thank you very much, mheadd gracias por pasarme ese enlace, lo mas curioso es que es en Espa�ol, no lo esperaba.

Thank you to all people.

Posts: 7 | Registered: Sep 2005  |  IP: Logged
MrBaseball34
Junior Member
Member # 3303

Rate Member
Icon 1 posted December 16, 2005 10:24 AM      Profile for MrBaseball34     Send New Private Message       Edit/Delete Post   Reply With Quote 
You can see how I do it in my reply to this post:
http://www.voicexml.org/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic;f=3;t=000060

Posts: 5 | Registered: Nov 2005  |  IP: Logged
blitzie
Junior Member
Member # 3370

Icon 1 posted February 02, 2006 11:01 AM      Profile for blitzie   Email blitzie   Send New Private Message       Edit/Delete Post   Reply With Quote 
Please, I badly need your help...
How can i get the values of a variable in PHP to a variable in VXML...
First, in the login page I get inputs from a user and save them in VXML variables (USERNAME & PASSWORD). Then i submit them to the SesRegister.php

Login.php
<submit next="SesRegister.php" method="" namelist="USERNAME PASSWORD"/>

Here, i am able to get the values from submitted VXML variables to PHP variables by "$_REQUEST". Then, upon navigating to the YourMenu.php I stil want to submit the USERNAME & PASSWORD, but it seems that there is something wrong with this line of code ... <submit next="YourMenu.php" method="" namelist="USERNAME PASSWORD"/> ... I don't know what's wrong with it, maybe the USERNAME & PASSWORD variables??? i Don't really know...

SesRegister.php
<?
$USER = $_REQUEST["USERNAME"];
$PASS = $_REQUEST["PASSWORD"];
$valid_user=$USER;
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
?>
<vxml version="2.0">
<prompt>You have signed in as <?=$valid_user?></prompt>
<submit next="YourMenu.php" method="" namelist="USERNAME PASSWORD"/>
</vxml>

Actually what I really wana do is to use Sessions in this application. But I'm a beginner in this VXML language so the only thing i could do is to pass the variables USERNAME & PASSWORD to all the pages.

Thank you so much...

Posts: 1 | Registered: Feb 2006  |  IP: Logged
mheadd
Member
Member # 3181

Member Rated:
4
Icon 1 posted February 02, 2006 01:07 PM      Profile for mheadd   Author's Homepage   Email mheadd   Send New Private Message       Edit/Delete Post   Reply With Quote 
You need to make a couple of changes to your script for it to work. You are catching the variables submitted to your script, but you need to print these values out in the VoiceXML markup

One way you can do this is by using the echo PHP language construct:

code:
<vxml version="2.0">
<prompt>You have signed in as <?php echo $valid_user; ?>.</prompt>
<submit next="YourMenu.php" method="" namelist="<?php echo $USER." ".$PASS; ?>"/>
</vxml>

Having said that, there are probably a number of security related changes that will want to implement if this comes anywhere near production.

1. Always validate input -- there are a number of ways of doing this. For some helpful info, check out this article.

2. Specify the method in your <submit> elements, and use the appropriate PHP superglobal array to catch it. For example:
code:
<submit next="SesRegister.php" method="post" namelist="USERNAME PASSWORD"/>

$USER = $_POST["USERNAME"];
$PASS = $_POST["PASSWORD"];

The $_REQUEST superglobal will accept data submitted through POST, GET or COOKIE so it is less secure. Since your controlling both sides of the operation, be more specific.

Session variables are a great idea, but you should be careful in how you use them. Generally speaking, it is a good practice to avoid including sensitive information (passwords, login IDs) in your VoiceXML markup. It's a good design practice to keep your presentation and business logic separated. So, instead of using session variables to echo out values in your VoiceXML markup like so:
code:
<?php
$_SESSION['user_id'] = 'henry';
$_SESSION['password'] = 'secret';
?>

<vxml version="2.0">
<var name="id" expr="<?php echo $_SESSION['user_id']; ?>"/>
<var name="pw" expr="<?php echo $_SESSION['password']; ?>"/>
...
<if cond="id=='henry' && pw=='secret'">
<goto next="sensitiveStuff.vxml"/>
</if>
...
</vxml>

Instead, use sessions variables to manage what markup to send to the VoiceXML interpreter:
code:
<?php
$_SESSION['LoggedIn'] = true;

if ($_SESSION['LoggedIn']) {

echo '<prompt>Get ready for some good stuff</prompt>';
echo '<goto next="somethingFun.vxml"/>';

} else {

echo '<prompt>You are not logged in.</prompt>';
echo '<goto next="login.vxml"/>';

}
?>

Hope this helps

--------------------
Mark
VoiceinGov.org
http://www.voiceingov.org

Posts: 55 | Registered: Jun 2005  |  IP: Logged


All times are Eastern  
Post New Topic  Post A Reply Close Topic    Move Topic    Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:

Contact Us | VoiceXML Forum



Powered by Infopop Corporation
UBB.classicTM 6.3.1.2