Re: asterisk with php
| From: | Jigar Dhulla | Date: | Wed, 22 Jul 2015 19:25:49 +0000 |
| Subject: | Re: asterisk with php | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-325010@lists.php.net to get a copy of this message | ||
On Wed, Jul 22, 2015 at 11:51 PM, hadi <almarzuki2011@hotmail.com> wrote:
> Hi,
>
> I have project, Asterisk with phpagi, when I pass variable to function I
> get
> error "Notice: Undefined variable: pin".
>
> Here is my code
>
>
>
> #!/usr/local/bin/php -q
> <?php
>
> error_reporting(E_ALL);
> ini_set('display_errors', 1);
>
> require("phpagi.php");
> require("database.php");
>
>
>
>
>
> $agi=new AGI();
>
>
>
> $agi->answer();
>
>
> for ($x = 0; $x <= 3; $x++)
> {
>
>
>
>
> $result = $agi->get_data('/var/lib/asterisk/agi-bin/ivr-sound1', 3000, 20);
>
>
> $pass = $result['result'];
>
>
> $query = $conn->prepare("SELECT COUNT(*) FROM userinfo where pin=:pin");
> $query->bindParam(':pin', $pass);
>
> $query->execute();
>
> $num_rows = $query->fetchColumn();
>
> if($num_rows == 1)
>
>
>
>
> {
> $agi->text2wav("thankyou");
>
>
>
> $agi->text2wav("please enter number to dial for more information press
> zero");
>
>
> $num = $agi->exec("Read","pin,,4,3,120");
>
> $temp = $agi->get_variable("pin");
>
> $pin = trim($temp["data"]);
>
> global $pin;
>
> break;
>
> }
>
>
> if ($x == 3)
>
> {
> $agi->hangup();
>
> }
>
> }
>
>
>
>
> dialout($pin);
>
>
> function
>
> dialout($pin)
>
> {
>
>
>
> $agi=new AGI();
>
> $agi->exec_dial("SIP/$pin");
>
> $Answeredtime = $agi->get_variable ("ANSWEREDTIME");
>
> $agi->hangup ();
>
>
> }
>
>
>
>
> ?>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Hi,
That "Notice" means you are trying to use/access that variable even though
it is not yet defined/set.
Looking at your code, if I am not wrong *$pin* is defined only when *$num_rows
== 1, *right ? Hence, when
*dialout($pin) *is called *$pin *will remain undefined in other cases,
so the notice(this is just one of the possibility).
So the best solution is to use *isset($pin) *where you think *$pin *can be
not defined/set.
*if(isset($pin) && !empty($pin)){*
* dialout($pin);*
*}*
Also in production/live environment, don't forget to suppress the
notice *error_reporting(E_ALL
& ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED); *you might not want
your users to see those notice or warning. Avoid suppressing such things in
development environment.
--
Regards,
Jigar Dhulla