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

Need a little help with my PHP script :)

Discussion in 'PHP & Perl' started by snakeccc, Feb 27, 2013.

  1. snakeccc

    snakeccc Junior Member

    Joined:
    Jan 23, 2012
    Messages:
    120
    Likes Received:
    104
    Occupation:
    SEO -> CPA -> $$$$
    Location:
    Bosna and Hercegovina
    I was trying to develop one script for my Fortumo SMS payment service.

    Here is API specification : http://developers.fortumo.com/api/service-setup

    But i have one problem , when i make payment i dont get any data inserted in my datebase. Can someone see my source and halp me a bit :)

    sms.php
    db.php


     
  2. inviz

    inviz Newbie

    Joined:
    Jun 15, 2010
    Messages:
    45
    Likes Received:
    5
    Hello!

    db.php looks ok, but no need to wrap the database connection into a function.. And add some error handling to get a better idea of whats going wrong....

    Change db.php to:

    PHP:
    <?php
    $conms 
    mysql_connect('localhost''admin''admin''fortumo');
    if (!
    $conms) {    
    die(
    'Could not connect: ' mysql_error());
    }
    ?>
    and the other file:

    PHP:
    <?php
    include ('db.php'); 
    //set true if you want to use script for billing reports
    //first you need to enable them in your account
    $billing_reports_enabled true;
    // check that the request comes from Fortumo server
    if (!in_array($_SERVER['REMOTE_ADDR'], array('81.20.151.38''81.20.148.122''79.125.125.1''209.20.83.207'))) {    
    header("HTTP/1.0 403 Forbidden");    
    die(
    "Error: Unknown IP");
    }
    // check the signature
    $secret '1c7b1bb53584d857df0e68a63bd3885f'// THIS IS MY TEST SERVICE SECRET CODE ''
    if (empty($secret) || !check_signature($_GET$secret)) {   
    header("HTTP/1.0 404 Not Found"); die("Error: Invalid signature");
    }
    $sender $_GET['sender'];
    $message $_GET['message'];
    $message_id $_GET['message_id']; //unique id
    $res mysql_query("INSERT INTO last_payment SET sender='$sender', message='$message',message_id='$message_id'")or die (mysql_error());
    //hint:use message_id to log your messages
    //additional parameters: country, price, currency, operator, keyword, shortcode
    // do something with $sender and $message
    $reply "$message unesite sledeci kod kada bude potrebno ($message_id)";
    // print out the reply
    echo($reply);
    //customize this according to your needs
    if ($billing_reports_enabled && preg_match("/Failed/i"$_GET['status']) && preg_match("/MT/i"$_GET['billing_type'])) {    
    // find message by $_GET['message_id'] and suspend it
    }
    function 
    check_signature($params_array$secret) {    
    ksort($params_array);
        
    $str '';    
    foreach (
    $params_array as $k => $v) {        
    if (
    $k != 'sig') {            
    $str .= "$k=$v";        
    }    
    }    
    $str .= $secret;    $signature md5($str);
        return (
    $params_array['sig'] == $signature);
    }
    ?>
    If the script is still not working, try to add:

    PHP:
    echo '<pre>';
    var_dump($_GET);
    right before the database query..

    post back with results.
     
    Last edited: Feb 28, 2013
  3. snakeccc

    snakeccc Junior Member

    Joined:
    Jan 23, 2012
    Messages:
    120
    Likes Received:
    104
    Occupation:
    SEO -> CPA -> $$$$
    Location:
    Bosna and Hercegovina
    It works now : i just made change on db.php

    Thanks a lot :)