1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Is there PHP solution for my problem ? Need Help !

Discussion in 'PHP & Perl' started by snakeccc, Dec 3, 2012.

  1. snakeccc

    snakeccc Junior Member

    Joined:
    Jan 23, 2012
    Messages:
    120
    Likes Received:
    104
    Occupation:
    SEO -> CPA -> $$$$
    Location:
    Bosna and Hercegovina
    I was coding somethng for my personal project, and now i need create automaticaly Fortumo script for every user on registracion.

    So this is SMS script that i need to create unique for every user..Unique param for every user is Fortumo Api Secret code. I'am noob now when i need to do that :D Every good replay can help. Thanks
    Code:
    [COLOR=#ff0000]<?php[/COLOR]
     
      [COLOR=#ff8c00]//set true if you want to use script for billing reports
      //first you need to enable them in your account[/COLOR]
      $billing_reports_enabled = [COLOR=#008000]false[/COLOR];
     
      [COLOR=#ff8c00]// check that the request comes from Fortumo server[/COLOR]
      [COLOR=#008000]if[/COLOR]([COLOR=#0000cd]!in_array[/COLOR]([COLOR=#40e0d0]$_SERVER[/COLOR][[COLOR=#ff0000]'REMOTE_ADDR'[/COLOR]],
          [COLOR=#0000cd]array[/COLOR]([COLOR=#ff0000]'81.20.151.38', '81.20.148.122', '79.125.125.1', '209.20.83.207'[/COLOR]))) {
        [COLOR=#0000cd]header[/COLOR]([COLOR=#ff0000]"HTTP/1.0 403 Forbidden"[/COLOR]);
        [COLOR=#0000cd]die[/COLOR]([COLOR=#ff0000]"Error: Unknown IP"[/COLOR]);
      }
     
      [COLOR=#ff8c00]// check the signature[/COLOR]
      $secret =[COLOR=#ff0000] ' '[/COLOR];[COLOR=#ff8c00] // secret between '' [/COLOR][COLOR=#fff0f5]<------ UNIQUE FOR EVERY USER![/COLOR]
      [COLOR=#008000]if[/COLOR]([COLOR=#0000cd]empty[/COLOR]($secret) || !check_signature($_GET, $secret)) {
        [COLOR=#0000cd]header[/COLOR]([COLOR=#ff0000]"HTTP/1.0 404 Not Found"[/COLOR]);
        [COLOR=#0000cd]die[/COLOR]([COLOR=#ff0000]"Error: Invalid signature"[/COLOR]);
      }
     
      $sender = [COLOR=#40e0d0]$_GET[/COLOR][[COLOR=#ff0000]'sender'[/COLOR]];
      $message = [COLOR=#40e0d0]$_GET[/COLOR][[COLOR=#ff0000]'message'[/COLOR]];
      $message_id = [COLOR=#40e0d0]$_GET[/COLOR][[COLOR=#ff0000]'message_id'[/COLOR]];//unique id
     
      [COLOR=#ff8c00]//hint:use message_id to log your messages
      //additional parameters: country, price, currency, operator, keyword, shortcode 
      // do something with $sender and $message[/COLOR]
      $reply =[COLOR=#ff0000] "Thank you $sender for sending $message"[/COLOR];
     
      [COLOR=#ff8c00]// print out the reply[/COLOR]
      [COLOR=#0000cd]echo[/COLOR]($reply);
     
     [COLOR=#ff8c00]//customize this according to your needs[/COLOR]
      [COLOR=#008000]if[/COLOR]($billing_reports_enabled 
        [COLOR=#0000cd]&& preg_match[/COLOR]([COLOR=#ff0000]"/Failed/i"[/COLOR],[COLOR=#40e0d0] $_GET[/COLOR][[COLOR=#ff0000]'status'[/COLOR]]) 
        [COLOR=#0000cd]&& preg_match[/COLOR]([COLOR=#ff0000]"/MT/i"[/COLOR], [COLOR=#40e0d0]$_GET[/COLOR][[COLOR=#ff0000]'billing_type'[/COLOR]])) {
       [COLOR=#ff8c00]// find message by $_GET['message_id'] and suspend it[/COLOR]
      }
     
      [COLOR=#0000cd]function[/COLOR] check_signature($params_array, $secret) {
        [COLOR=#0000cd]ksort[/COLOR]($params_array);
     
        $str = [COLOR=#ff0000]''[/COLOR];
        [COLOR=#008000]foreach [/COLOR]($params_array [COLOR=#008000]as[/COLOR] $k[COLOR=#0000cd]=>[/COLOR]$v) {
          [COLOR=#008000]if[/COLOR]($k != [COLOR=#ff0000]'sig'[/COLOR]) {
            $str .= "$k=$v";
          }
        }
        $str .= $secret;
        $signature = [COLOR=#0000cd]md5[/COLOR]($str);
     
        [COLOR=#008000]return[/COLOR] ($params_array['sig'] [COLOR=#0000cd]==[/COLOR] $signature);
      } 
    [COLOR=#ff0000]?>
    
    [/COLOR]
     
    Last edited by a moderator: Dec 3, 2012
  2. alias_unknown

    alias_unknown Newbie

    Joined:
    Dec 30, 2012
    Messages:
    41
    Likes Received:
    4
    I'd approach it by storing the API keys etc for each user in a database table. Then with the script above I would send in a user id (which appears to be the sender id in the script), with this user id I would pull all the necessary keys from the table and put it into the variables on the page. You don't need to have a separate script for each user. What needs to be done is basic PHP / MySQL skills.