Please help wit my sms script

Discussion in 'PHP' started by scara, Dec 25, 2007.

  1. #1
    <title>Free SMS-Send Free SMS now</title>
    </head>
    <body>
    
    <?
    include('chk_ban.php');
    
    //rest van de pagina hieronder
    ?>
    // Settings
    $footer = '- www.yourpage.com'; // site-ul tau sau o reclama
    $maxSizeSms = 160 - strlen($footer); // caractere ramase (dupa footer)
    
    DEFINE('API_USER', 'smsuser');
    DEFINE('API_PWD', 'smspass');
    DEFINE('FROM', 'smspage');
    
    if( !extension_loaded('curl') ){
            die('Trebuie sa incarci/activezi extensia php curl (http://www.php.net/cURL).');
    }
    
    // verifica daca form-ul a fost "posted"
    if( isset($_GET['mobile']) && isset($_GET['sms']) ){
    
            // nr tel + mesaj (mesaj + footer)
            preg_match_all('/[\d]{11}/', $_GET['mobile'], $mobile);
            $sms = urlencode(substr($_GET['sms'], 0, $maxSizeSms).$footer);
    
            // URL pt trimiterea sms-ului
            $apiCallUrl  = 'https://yourserver.com/sendsms.php?';
            $apiCallUrl .= '&username='.API_USER.'&password='.API_PWD;
            $apiCallUrl .= '&to='.$mobile[0][0].'&text='.$sms.'&from='.FROM;
    
            // cURL info la <http://www.php.net/cURL> si <http://curl.haxx.se/docs/features.html>
            $curlHandle = curl_init(); // init curl
    
            // cURL options
            curl_setopt($curlHandle, CURLOPT_URL, $apiCallUrl); // adresa ce urmeaza sa fie accesata
            curl_setopt($curlHandle, CURLOPT_HEADER, 0); // headers (0 = fara headers in rezultat)
            curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); // tipul de transfer (1 = string)
            curl_setopt($curlHandle, CURLOPT_TIMEOUT, 15); // timp de asteptare in sec
            curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER,0); // fara verificare ssl
    
            $content = curl_exec($curlHandle); // Pasul final pt trimiterea sms-ului
    
            curl_close($curlHandle); // Inchid conexiunea
    
            if( preg_match('/fa/i', $content) ){
            header('Location: notok.html');
                   echo '<h2>Message Not SENT!</h2>';
            }else{
            header('Location: ok.html');
                    echo '<h2>Mesage has been SENT!</h2>';
            }
    }
    ?>
    
    
    <form method="get" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
    
    Phone number (formatul 4072xxxxxx)<br />
    <input type="text" name="mobile" size="11" maxlength="12" value="40" /><br />
    
    Mesage text (max <?php echo $maxSizeSms ?> caracters)<br />
    <input type="text" name="sms" size="30" maxlength="<?php echo $maxSizeSms ?>" value="" /><br />
     <br>
    
    <input type="submit" value="Send SMS" />
    
    
    </form>
    </body>
    </html>
    
    
    
    PHP:
    This is my script,i want to build a php-drop-down list wit at least 2-3 countries sow i can add more.The only thing i need is to enter automatically the country code,and users to select their contry and just enter phone number (script must insert automatically C.code)
    Im novice in php codding and i ask if someone can help me wit this problem.
    Or at least to make country code like is set now (40) unmodifiable (the users cannot change the contry code)

    Thank in advance, i hope some people will be kind to help me!
     
    scara, Dec 25, 2007 IP
  2. dataman

    dataman Peon

    Messages:
    94
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Replace this...

    include('chk_ban.php');
    PHP:

    With This...

    include('chk_ban.php');
    
    $codes = array ( 
    array ( 
    	'code' => 40, 'country' => 'Country One'
    	), 
    array ( 
    	'code' => 30, 'country' => 'Country Two'
    	), 
    array ( 
    	'code' => 10, 'country' => 'Country Three'
    	)
    );
    
    $default_code = 40;
    
    function code_check ( $a, $b, &$c )
    {
    	$ok = false;
    
    	foreach ( $codes AS $k => $v )
    	{
    		if ( $b == $v['code'] )
    		{
    			$ok = true;
    			$c = $b;
    			break;
    		}
    	}
    
    	return $ok;
    }
    
    PHP:
    Replace this...

    if( isset($_GET['mobile']) && isset($_GET['sms']) ){
    PHP:

    With this...

    if ( isset ( $_GET['mobile'] ) && isset ( $_GET['code'] ) && isset ( $_GET['sms'] ) && code_check ( $codes, $_GET['code'], $default_code ) )
    {
    PHP:



    Replace this...

    
    Phone number (formatul 4072xxxxxx)<br />
    <input type="text" name="mobile" size="11" maxlength="12" value="40" /><br />
    PHP:
    With This...

    
    Country Code (Select)
    <br />
    <select name='code'>
    <?php
    	foreach ( $codes AS $k => $v )
    	{
    		echo "\t<option value='" . $v['code'] . "'" . ( $default_code == $v['code'] ? " selected='selected'" : "" ) . "> " . $v['country'] . "</option>
    ";
    	}
    ?>
    </select>
    <br />
    Phone number (formatul 4072xxxxxx)<br />
    <input type="text" name="mobile" size="11" maxlength="12" value="" /><br />
    PHP:


    Then in your CURL code, you use $default_code, which represents the selected country code or default country code when no valid code was selected!
     
    dataman, Dec 25, 2007 IP
  3. scara

    scara Active Member

    Messages:
    96
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #3
    scara, Dec 25, 2007 IP
  4. scara

    scara Active Member

    Messages:
    96
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #4
    <title>Free SMS-Send Free SMS now</title>
    </head>
    <body>
    
    <?
    include('chk_ban.php');
    
    $codes = array (
    array (
        'code' => 40, 'country' => 'Romania'
        ),
    array (
        'code' => 49, 'country' => 'Germany'
        ),
    array (
        'code' => 43, 'country' => 'Austria'
        ),
    array (
        'code' => 33, 'country' => 'France'
        ),
    array (
        'code' => 36, 'country' => 'Hungary'
        ),
    array (
        'code' => 62, 'country' => 'Indonezia'
        ),
    array (
        'code' => 31, 'country' => 'Netherland'
        ),
    array (
        'code' => 48, 'country' => 'Poland'
        ),
    array (
        'code' => 351, 'country' => 'Portugal'
        ),
    array (
        'code' => 7, 'country' => 'Rusia Federation'
        ),
    array (
        'code' => 381, 'country' => 'Serbia&Montenegro'
        ),
    array (
        'code' => 41, 'country' => 'Switzerland'
        ),
    array (
        'code' => 1, 'country' => 'United States'
        ),
    array (
        'code' => 49, 'country' => 'empty'
        ),
    array (
        'code' => 49, 'country' => 'empty'
        )
    
    );
    
    $default_code = 40;
    
    function code_check ( $a, $b, &$c )
    {
        $ok = false;
    
        foreach ( $codes AS $k => $v )
        {
            if ( $b == $v['code'] )
            {
                $ok = true;
                $c = $b;
                break;
            }
        }
    
        return $ok;
    }
    
    //rest van de pagina hieronder
    ?>
    
    
    <?php
    // Copyright (c) 2007, Luci <http://www.luci.ws> all rights reserved.
    
    // Setari
    $footer = '- www.yoursite.com; // site-ul tau sau o reclama
    $maxSizeSms = 160 - strlen($footer); // caractere ramase (dupa footer)
    
    DEFINE('API_USER', 'apiuser');
    DEFINE('API_PWD', 'apipass');
    DEFINE('FROM', 'fromwho');
    
    if( !extension_loaded('curl') ){
            die('Trebuie sa incarci/activezi extensia php curl (http://www.php.net/cURL).');
    }
    
    // verifica daca form-ul a fost "posted"
    if ( isset ( $_GET['mobile'] ) && isset ( $_GET['code'] ) && isset ( $_GET['sms'] ) && code_check ( $codes, $_GET['code'], $default_code ) )
    {        // nr tel + mesaj (mesaj + footer)
            preg_match_all('/[\d]{11}/', $_GET['mobile'], $mobile);
            $sms = urlencode(substr($_GET['sms'], 0, $maxSizeSms).$footer);
    
            // URL pt trimiterea sms-ului
            $apiCallUrl  = 'https://www.yoursite.com/sendsms.php?';
            $apiCallUrl .= '&username='.API_USER.'&password='.API_PWD;
            $apiCallUrl .= '&to='.$mobile[0][0].'&text='.$sms.'&from='.FROM;
    
            // cURL info la <http://www.php.net/cURL> si <http://curl.haxx.se/docs/features.html>
            $curlHandle = curl_init(); // init curl
    
            // cURL options
            curl_setopt($curlHandle, CURLOPT_URL, $apiCallUrl); // adresa ce urmeaza sa fie accesata
            curl_setopt($curlHandle, CURLOPT_HEADER, 0); // headers (0 = fara headers in rezultat)
            curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); // tipul de transfer (1 = string)
            curl_setopt($curlHandle, CURLOPT_TIMEOUT, 15); // timp de asteptare in sec
            curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER,0); // fara verificare ssl
    
            $content = curl_exec($curlHandle); // Pasul final pt trimiterea sms-ului
    
            curl_close($curlHandle); // Inchid conexiunea
    
            if( preg_match('/fa/i', $content) ){
            header('Location: notok.html');
                   echo '<h2>Message Not SENT!</h2>';
            }else{
            header('Location: ok.html');
                    echo '<h2>Mesage has been SENT!</h2>';
            }
    }
    ?>
    
    
    <form method="get" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
    
    Country Code (Select)
    <br />
    <select name='code'>
    <?php
        foreach ( $codes AS $k => $v )
        {
            echo "\t<option value='" . $v['code'] . "'" . ( $default_code == $v['code'] ? " selected='selected'" : "" ) . "> " . $v['country'] . "</option>
    ";
        }
    ?>
    </select>
    <br />
    Phone number (formatul 72xxxxxx fara cod de tara)<br />
    <input type="text" name="mobile" size="11" maxlength="12" value="" /><br />
    
    Mesage text (max <?php echo $maxSizeSms ?> caracters)<br />
    <input type="text" name="sms" size="30" maxlength="<?php echo $maxSizeSms ?>" value="" /><br />
     <br>
    
    <input type="submit" value="Send SMS" />
    
    
    </form>
    </body>
    </html>
    
    
    
    PHP:
    Can somebody tell me wat is wrong?
    I dond get the status if is send or not.

    Then in your CURL code, you use $default_code, which represents the selected country code or default country code when no valid code was selected!
    Code (markup):
    wat are you meen? were i have to modify that?
     
    scara, Dec 25, 2007 IP