注意:使用未定义的常量方法 - 假设

时间:2016-03-07 10:16:29

标签: php

您好我在php中使用短信发送器,我收到此错误

Notice: Use of undefined constant method - assumed

这是我的代码

<?php
////////
/* Sender SMS */
////////

    $request =""; //initialise the request variable
    $param[method]= "sendMessage";
    $param[send_to] = "91".$_SESSION['yourContact'];
    $param[msg] = "vamsi biyah hello the sms is working ahhahahahah  :D :D " . $_SESSION['tour_id'] . "";
    $param[userid] = $sms_userid;
    $param[password] = $sms_pass;
    $param[v] = "1.1";
    $param[msg_type] = "TEXT"; //Can be "FLASH”/"UNICODE_TEXT"/”BINARY”
    $param[auth_scheme] = "PLAIN";
    //Have to URL encode the values
    foreach($param as $key=>$val) {
        $request.= $key."=".urlencode($val);
    //we have to urlencode the values
        $request.= "&";
    //append the ampersand (&) sign after each parameter/value pair
    }
    $request = substr($request, 0, strlen($request)-1);
    //remove final (&) sign from the request
    $url = "http://enterprise.smsgupshup.com/GatewayAPI/rest?".$request;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $curl_scraped_page = curl_exec($ch);
    curl_close($ch);
    //echo $curl_scraped_page;

?>

这就是我得到的错误:

Notice: Use of undefined constant method - assumed 'method'
Notice: Use of undefined constant send_to - assumed 'send_to'
Notice: Use of undefined constant msg - assumed 'msg'
Notice: Use of undefined constant userid - assumed 'userid'
Notice: Use of undefined constant password - assumed 'password'
Notice: Use of undefined constant v - assumed 'v'
Notice: Use of undefined constant msg_type - assumed 'msg_type' 
Notice: Use of undefined constant auth_scheme - assumed 'auth_scheme'

任何人都可以帮我理解这个错误是什么,我该如何解决?

2 个答案:

答案 0 :(得分:1)

您需要为索引使用引号,否则它将被视为常量变量:

示例:

$param['method']= "sendMessage";
$param['send_to'] = "91".$_SESSION['yourContact'];
$param['msg'] = "vamsi biyah hello the sms is working ahhahahahah  :D :D " . $_SESSION['tour_id'] . "";
$param['userid'] = $sms_userid;
$param['password'] = $sms_pass;
$param['v'] = "1.1";
$param['msg_type'] = "TEXT"; //Can be "FLASH”/"UNICODE_TEXT"/”BINARY”
$param['auth_scheme'] = "PLAIN";

答案 1 :(得分:0)

尝试使用'作为数组项,例如

$param['method']它可以解决您的问题