mosey Posted August 26, 2007 Share Posted August 26, 2007 I'm afraid this is a bit of a long winded introduction for what I think would be a simple question: For reference, I'm trying to modify the SMS API kindly provided at Sourceforge (http://sourceforge.net/projects/sms-api/) to something that will send WAP PUSH messages. I have tried my best to modify it as much as I can without changing the essentials, but for some reason, I keep receiving an fopen error built into the script that informs me the script has died. The original (almost) working SMS API is something like this (with all the unnecssary bits cut out): function send($to=null, $from=null, $text=null, $msg_type=null, $climsgid=null) { /* Check SMS credits balance */ if ($this->getbalance() < $this->balace_limit) { die ("You have reach the SMS credit limit!"); }; /* Check SMS $text length */ if ($this->unicode == true) { $this->_chk_mbstring(); if (mb_strlen ($text) > 210) { die ("Your unicode message is to long! (Current length".mb_strlen ($text).")"); } /* Does message need to be concatenate */ if (mb_strlen ($text) > 70) { $concat = "&concat=3"; } else { $concat = ""; } } else { if (strlen ($text) > 465) { die ("Your message is to long! (Current length=".strlen ($text).")"); } /* Does message need to be concatenate */ if (strlen ($text) > 160) { $concat = "&concat=3"; } else { $concat = ""; } } /* collect message type from form */ $msg_type = $_POST["msg_type"]; /*collect client message id */ $climsgid = $_POST["climsgid"]; /*collect priority value */ $escalate = $_POST["escalate"]; /* Check $to and $from is not empty */ if (empty ($to)) { die ("You have not specified a destination address (TO)!"); } if (empty ($from)) { die ("You have not specified a source address (FROM)!"); } if (empty ($msg_type)) { die ("You have not specified a message type (MESSAGE TYPE)!"); } /* Reformat $to number */ $cleanup_chr = array ("+", " ", "(", ")", "\r", "\n", "\r\n"); $to = str_replace($cleanup_chr, "", $to); /* Send SMS now */ $comm = sprintf ("%s/sendmsg?session_id=%s&to=%s&from=%s&text=%s&msg_type=%s&climsgid=%s&escalate=%s&callback=%s&unicode=%s%s", $this->base, $this->session, rawurlencode($to), rawurlencode($from), $this->encode_message($text), $msg_type, $climsgid, $escalate, $this->callback, $this->unicode, $concat ); return $this->_parse_send ($this->_execgw($comm)); } /** * Encode message text according to required standard * @param text mixed Input text of message. * @return mixed Return encoded text of message. * @access public */ function encode_message ($text) { if ($this->unicode != true) { //standard encoding return rawurlencode($text); } else { //unicode encoding $uni_text_len = mb_strlen ($text, "UTF-8"); $out_text = ""; //encode each character in text for ($i=0; $i<$uni_text_len; $i++) { $out_text .= $this->uniord(mb_substr ($text, $i, 1, "UTF-8")); } return $out_text; } } /** * Execute gateway commands * @access private */ function _execgw($command) { if ($this->sending_method == "curl") return $this->_curl($command); if ($this->sending_method == "fopen") return $this->_fopen($command); die ("Unsupported sending method!"); } /** * fopen sending method * @access private */ function _fopen($command) { $result = ''; $handler = @fopen ($command, 'r'); if ($handler) { while ($line = @fgets($handler,1024)) { $result .= $line; } fclose ($handler); return $result; } else { die ("Error while executing fopen sending method!<br>Please check does PHP have OpenSSL support and check does PHP version is greater than 4.3.0."); } } /** * Parse authentication command response text * @access private */ function _parse_auth ($result) { $session = substr($result, 4); $code = substr($result, 0, 2); if ($code!="OK") { die ("Error in SMS authorization! ($result)"); } return $session; } /** * Parse send command response text * @access private */ function _parse_send ($result) { $code = substr($result, 0, 2); if ($code!="ID") { die ("Error sending SMS! ($result)"); } else { $code = "OK - The message id is #$apiMsgId"; } return $code; } The only parts I've changed are: function send($to=null, $from=null, $climsgid=null, $si_url=null, $si_text=null) { /* Check SMS credits balance */ if ($this->getbalance() < $this->balace_limit) { die ("You have reach the credit limit!"); }; /* Check $to and $from is not empty */ if (empty ($to)) { die ("You did not specify destination address (TO)!"); } if (empty ($from)) { die ("You did not specify source address (FROM)!"); } if (empty ($si_url)) { die ("You did not specify the URL (URL)!"); } if (empty ($si_text)) { die ("You did not specify the message (Message)!"); } /* Reformat $to number */ $cleanup_chr = array ("+", " ", "(", ")", "\r", "\n", "\r\n"); $to = str_replace($cleanup_chr, "", $to); /* Pickup extra values */ $climsgid = $_POST["climsgid"]; $si_url = $_POST["si_url"]; $si_text = $_POST["si_text"]; $si_action = $_POST["si_action"]; /* Send Wap Push now */ $comm = sprintf ("%s/si_push?session_id=%s&to=%s&from=%s&climsgid=%s&si_id&si_url=%s&si_text=%s&si_created&si_expires&si_action=%s%s", $this->base, $this->session, $this->api_id, $this->user, $this->password, rawurlencode($to), rawurlencode($from), $climsgid, rawurlencode($si_url), $this->encode_message($si_text), $si_action, $concat ); return $this->_parse_send ($this->_execgw($comm)); } /** * Encode message text according to required standard * @param text mixed Input text of message. * @return mixed Return encoded text of message. * @access public */ function encode_message ($si_text) { if ($this->unicode != true) { //standard encoding return rawurlencode($si_text); } else { //unicode encoding $uni_text_len = mb_strlen ($si_text, "UTF-8"); $out_text = ""; //encode each character in text for ($i=0; $i<$uni_text_len; $i++) { $out_text .= $this->uniord(mb_substr ($si_text, $i, 1, "UTF-8")); } return $out_text; } } And the error I receive is : to check that PHP > 4.3 and server supports OpenSSL, which I know it does, because the first SMS part works. I have a feeling it's the way I've concatenated the string, which is causing the fopen error. So would really appreciate it if anyone had any suggestions as I'm really starting to pull my hair out >_< Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/66776-fopen-a-concatenated-string/ Share on other sites More sharing options...
schme16 Posted August 26, 2007 Share Posted August 26, 2007 Apart from the obvious question of : are your files where your telling php to look? I'd also ask, are your folder 755 CHMOD'd? Quote Link to comment https://forums.phpfreaks.com/topic/66776-fopen-a-concatenated-string/#findComment-334625 Share on other sites More sharing options...
mosey Posted August 26, 2007 Author Share Posted August 26, 2007 Hi schme16, thanks for your reply As far as I've understood the script, it's not really calling a local file but just picking up variables from a form submission,concatenating it into one string, and then using fopen to load the string; but I will check again that all the values are valid etc. With regards to the second question: I've just checked it (thanks) and it is 755. The file is actually in the same folder as the work SMS API, so hopefully this means the settings are ok. Quote Link to comment https://forums.phpfreaks.com/topic/66776-fopen-a-concatenated-string/#findComment-334674 Share on other sites More sharing options...
schme16 Posted August 27, 2007 Share Posted August 27, 2007 fopen isn't used for collecting form data, its used for opening a file (either locally or via a URL wrapper). To handle form data use $_POST['name_of_form input']. Hope this helps at all Quote Link to comment https://forums.phpfreaks.com/topic/66776-fopen-a-concatenated-string/#findComment-335105 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.