SHARE
TWEET

SMS Gateway php demo

a guest Jun 3rd, 2012 33,349 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /*
  4. This demo shows how to handle requests from SMS Gateway with full UTF-8 support and send reply SMS back
  5. */
  6.  
  7. //setup PHP UTF-8 stuff
  8. setlocale(LC_CTYPE, 'en_US.UTF-8');
  9. mb_internal_encoding("UTF-8");
  10. mb_http_output('UTF-8');
  11.  
  12.  
  13. //read parameters from HTTP Get URL
  14. $phone = $_GET["phone"];
  15. $smscenter = $_GET["smscenter"];
  16. $text_utf8 = rawurldecode($_GET["text"]);
  17.  
  18. //if parameters are not present in HTTP url, they can be also present in HTTP header
  19. $headers = getallheaders();
  20. if (empty($phone)) {
  21.         $phone = $headers["phone"];
  22. }
  23. if (empty($smscenter)) {
  24.         $smscenter = $headers["smscenter"];
  25. }
  26. if (empty($text_utf8)) {
  27.         $text_utf8 = rawurldecode($headers["text"]);
  28. }
  29.  
  30.  
  31.  
  32. //create reply SMS
  33. $reply_utf8 = mb_strtoupper($text_utf8); // mare reply message uppercased input message
  34.  
  35. //write reply to HTTP header
  36. $reply_header = rawurlencode($reply_utf8);
  37. header('Content-Type: text/html; charset=utf-8');
  38. header("text: $reply_header"); //if you don't want reply sms, comment out this this line
  39.  
  40.  
  41. // Debug outputs:
  42. //echo "phone = $phone\n";
  43. //echo "smscenter = $smscenter\n";
  44. //echo "text_utf8 = $text_utf8\n";
  45. //echo "reply_utf8 = $reply_utf8\n";
  46. ?>
RAW Paste Data
Top