Posts

Ultimate Guide to send OTP using PHP(Twilio) in 5 minutes?

Are you facing an increase in attempts by spam to gain unauthorized access to your website? Once you’ve launched your website and you haven’t put any spam prevention measure in place. Verification Code allows you to protect your website by adding send sms verification functionality to User Registration functions before the user can see the full content of your website.

Verification Code is used Twilio Networks HTTP API to send messages, meaning you will need a valid Twilio Networks username and password in order to be able to send SMS messages. The account can be obtained from the https://www.twilio.com

Basic Php Integration to Send SMS with Twilio

1. How to Setup Twilio

To send SMS and outgoing messages perform an HTTP POST to the Messages resource URI. We will also use the Twilio PHP Library for making REST requests.

If you are using a Twilio Trial account for this example, you will only be able to send SMS messages to phone numbers that you have verified with Twilio. Phone numbers can be verified via your Twilio Console’s Verified Caller IDs. The ‘From’ parameter will also need to be a phone number you purchased from Twilio.

Create an account on Twilio.

  • Follow this link for create account on Twilio https://www.twilio.com.
  • If you created trial account on Twilio then you can send SMS to only the verified number of Twilio account.
  • For send SMS on any number you need to create premium account or upgrade the Twilio account.

2. Scheduled SMS campaigns

You’ll be assigned a number when you sign up to Twilio that you can use for testing but can’t send any actual texts through it. We just credited the account straight away so we could see the text coming through live. For us and probably most others we only needed to send a handful of texts whilst testing. As you’ll see further down this write up the library provided by Twilio is super simple and you are only charged when a text is successfully delivered so for the cost of having the convenience of actual messages being delivered to real phones was well worth it.

Sign up for a free Twilio account and buy a phone number.

3. Grab the PHP library and your API credentials

Download the PHP library provided by Twilio and put it somewhere that it can be included in the PHP script you want to use to send the SMS text. When sending your messages you’ll also need your account sid and your Auth Token. These can be grabbed from your account settings.

4. Set up the sending of the message

Firstly include the PHP library you’ve just downloaded and unzipped:

require "PATH YOUR TWILIO LIBRARY/Services/Twilio.php";
$client = new Services_Twilio('ACCOUNT SID HERE', 'AUTHTOKENHERE');

You have to find the your account SID and auth token in your console dashboard, and your phone number in your phone numbers list. Create a file called settings.php to store these values.

 
     $account_sid = "YOURACCOUNTSID";
     $auth_token = "YOURAUTHTOKEN";
     $twilio_phone_number = "+YOURTWILIONUMBER";

Create a file called send-sms.php and paste in the code below to:

  • Include the helper library and settings file
  • Create a Twilio client using our account credentials
  • Create a new message from our twilio number, to our cellphone
require "PATH YOUR TWILIO LIBRARY/Services/Twilio.php";
include 'settings.php';
$client = new Services_Twilio('ACCOUNT SID HERE', 'AUTHTOKENHERE'); 
$client->account->messages->create(array(
  'To' => 'NUMBER OF RECIPIENT',
  'From' => 'NUMBER PURCHASED WITH YOUR ACCOUNT',
  'Body' => "THIS IS YOUR TEXT MESSAGE",
));

Save your file and run it:
php send-sms.php

Conculsion

It’s as easy as that! You’ll now be sending live text messages via PHP and Twilio. You can keep an eye on the outgoing messages via the logs area of your Twilio account area and keep an eye on costs via the usage area.
Following on from that we set the header type text/plain and simply output what we’d like to be text back to the number that has sent the text, Twilio does the rest. That’s sending a text messages and handling a response via a text all wrapped with small amount of code.

References

Twilio Docs
The Twilio Php Helper Library
SEND SMS AND MMS MESSAGES IN PHP

Further Reading

Twilio voice: Receive Call On Your Android Mobile
Easy way to play an audio file on call in android using twilio
How to enable two step verification in Socialengine websites

How to create a autocomplete profile question in SocialEngine?

We are developing a community website application where we have different profiles of the user and their information. These profile types are not limited we want to add a new profile whenever we want and they have their own question. SocialEngine is one of the best tools to develop an online community. It is highly manageable, flexible and scalable and user-friendly. SocialEngine is best suited for our requirement that’s why we have decided to go with the SocialEngine. But we stuck at a point where we need a socialengine autocomplete profile question, which is out of the box in SocialEngine. We have decided to add a form element in the form but later on, we realize that whenever we add a new profile type we need a SocialEngine developer to customize the solution which is not a good approach. We want a dynamic solution like First Name or Gender(that already exist) field in SocialEngine. So the problem is how we create this type of element so that it can be added dynamically as a question of the different profile type. To find the best solution we have uses the following approach this might helps others.
Step1. Register a new form element: First, we need to register our new element with SocialEngine. Add the following code inside the application/modules/Fields/settings/fields.php

 'jobposition' => array(
        'base' => 'text',
        'label' => 'Job Position',
        'category' => 'specific',
 ),

Step2. Create your form element: Now create your element, Navigate to the application/modules/Fields/Form/Element and create a file Jobposition.php. Here my element name is ‘jobposition’. In the following code, we are creating a autocomplete field element which derived from Text element type.

class Fields_Form_Element_Jobposition extends Engine_Form_Element_Text{
    public function init()
    {
       
        $this->setAttrib('module', 'sciencejnr');
        $this->setAttrib('controller', 'article');
        $this->setAttrib('action', 'jobposition');
    }

    public function loadDefaultDecorators()
    {
        if( $this->loadDefaultDecoratorsIsDisabled() )
        {
            return;
        }

        $decorators = $this->getDecorators();
        if( empty($decorators) )
        {
            $this->addDecorator('JobPositionWrapper');
            Engine_Form::addDefaultDecorators($this);
        }
    }
}

Step3. Create a decorator: Now we have to create a decorator class to render the new element in the form. Navigate to the application/libraries/Engine/Form/Decorator and create a file jobPostionWrapper.php and add the following code.

class  Engine_Form_Decorator_JobPositionWrapper extends Zend_Form_Decorator_Abstract
{
    /**
     * Default placement: surround content
     * @var string
     */
    protected $_placement = null;

    /**
     * Render
     *
     * Renders as the following:
     *
     * @param  string $content
     * @return string
     */
    public function render($content)
    {
        $elementName = $this->getElement()->getName();

        $url = $this->getElement()->getAttrib('url');
        $module = $this->getElement()->getAttrib('module');
        $controller = $this->getElement()->getAttrib('controller');
        $action = $this->getElement()->getAttrib('action');
        if( $url ) {
            $this->getElement()->setAttrib('url', null);

        }
        if( $module ) {
            $this->getElement()->setAttrib('module', null);
        }
        if( $controller ) {
            $this->getElement()->setAttrib('controller', null);
        }
        if( $action ) {
            $this->getElement()->setAttrib('action', null);
        }
        $view = $this->getElement()->getView();
        return $view->partial('suggest/suggest.tpl', 'fields', array(
            'name' => $elementName,
            'url' => $url,
            'element' => $this->getElement(),
            'module' => $module,
            'controller' => $controller,
            'action' =>$action
        ));

    }
}

Step4. Create a tpl file to add an HTML and javascript static code:  Here is the example of html code. Navigate to the application/modules/Fields/views/scripts/suggest and create a file suggest.tpl and add the following to the tpl file:

$this->headScript()
    ->appendFile($this->layout()->staticBaseUrl . 'application/modules/Seaocore/externals/scripts/autocompleter/Autocompleter.js');
$elementName = $this->name;
$module = $this->module;
$ctl = $this->controller;
$action = $this->action;
$element = $this->element;
$name = explode('_', $elementName);

Html:
html
Javascript:

        new Autocompleter.Request.JSON(element, '', {
            'minLength': 1,
            'delay' : 250,
            'selectMode': 'pick',
            'autocompleteType': 'message',
            'multiple': false,
            'className': 'message-autosuggest',
            'filterSubset' : true,
            'tokenFormat' : 'object',
            'tokenValueKey' : 'label',
            'elementValues': 'toValues',
            'injectChoice': function(token){
                //console.log(token);
                var choice = new Element('li', {
                    'class': 'autocompleter-choices friendlist',
                    'id':token.label
                });
                new Element('div', {
                    'html': this.markQueryValue(token.label),
                    'class': 'autocompleter-choice'
                }).inject(choice);
                this.addChoiceEvents(choice).inject(this.choices);
                choice.store('autocompleteChoice', token);
            }
            , onPush : function(){
                $('').setStyle('display', 'none');
                //$('-toVales-wrapper').setStyle('display', 'block');
                $('').disabled = true;
            }
        });
    function removeFromToValue(id,id2,id3,id4) {
        // code to change the values in the hidden field to have updated values
        // when recipients are removed.
        var toValues = $(id4).value;
        var toValueArray = toValues.split(",");
        var toValueIndex = "";
        var checkMulti = id.search(/,/);

        // check if we are removing multiple recipients
        if (checkMulti!=-1){
            var recipientsArray = id.split(",");
            for (var i = 0; i < recipientsArray.length; i++){
                removeToValue(recipientsArray[i], toValueArray, id3);
            }
        }
        else{
            removeToValue(id, toValueArray, id3);
        }

        // hide the wrapper for usernames if it is empty
        if ($(id3).value==""){
            $(id4+'-wrapper').setStyle('height', '0');
        }

        $(id3).disabled = false;
        $(id3).setStyle('display', 'block');
       // $(id4+'-wrapper').setStyle('display', 'none')
    }
    function removeToValue(id, toValueArray, id4){
        for (var i = 0; i < toValueArray.length; i++){
            if (toValueArray[i]==id) toValueIndex =i;
        }
        toValueArray.splice(toValueIndex, 1);
        $(id4).value = toValueArray.join();
    }

Step5. Now add this new element type as profile question: To add question to the profie type use the default approach of SocialEngine. Selectt the job posiotn while selecting the question type as shown in the image:
profile-question
And in the form this will show you like this:

autocomplete

Conclusion:

This article explains creating a autocomplete form element in socailEngine so that we can create socialengine autocomplete profile question for the profile types. Autocomplete is the most used form elements nowadays due to less input error. It suggests the user enter a valid data. If any better approach or solution your thought are most welcome. Please share with us so that it might help others aswell.

Reference:

SocialEngine

Zend

Top 5 Reasons why your online community needs mobile app

Do you have an online community? Would you like to improve user engagement on it ? One of the solutions is your online community needs a mobile app, because it will not only bring a large amount of user but also give an opportunity to access your community anytime and anywhere. More and more small and midsize businesses are following the mobile trend, understanding that an effective mobile strategy involves more than just a mobile-friendly website.

In fact, these days you’ll notice that many small businesses you interact with in your everyday life have their own dedicated mobile app — be it the corner coffee shop or the beauty spa downtown. These companies are ahead of the game when it comes to taking their marketing to the next level.

In this article, we have highlighted 5 reasons why we think mobile apps should be an important cornerstone of your online community. Below are the reasons why your online community needs mobile app:

1. Online community needs mobile app to improve User Engagement

No matter whether you are selling flowers or have a community for your family and friends, everyone needs a way to reach you. Having a messaging (or help desk) feature within your app can really make a difference in the way you communicate with your people. You can post messages to notify the members about a certain event; you can host debates and discussions among the members and keep the community active.

2. Be Visible to community member at All Times

We are attached to our mobile devices at the palms, and fingertips. We are never without our phones and we love using them everywhere from waiting for the bus or when we are on any trip. We can not carry our laptop everywhere and anytime, bu tit is easy to carry our mobile. It gives you a special opportunity to be with your community member at all time. We love the ability to share whenever we have a free second, and mobile devices allow us to be attached from anywhere at anytime.

3. Provide Value to Your Member

It allows more flexibility and can address specific member’s needs. You can text individually, sharing your personal thought that you do not want to share with other members of the community. You can create events or groups and can invite individually to any member. It makes you present yourselves to any member at any time and make them feel special and important

4. Build Brand and Recognition

The professionalism you show will increase trust and recognition by your targeted audience through your app. By having a mobile app, businesses get placed in the consumer’s pocket and are with them all the time. For your business what you really want to do is create an app that has features your customers will love while at the same time is well branded and beautifully designed.  The more often you can get customers involved with your app, the sooner they will be inclined to buy your product and/or service.

5. Cultivate Customer Loyalty

The most important reason why your online community needs a mobile app ,especially for your business , is customer loyalty. Other mediums like roadside banners, billboards, flashing signs, newspaper ads, flyers, coupons, websites, website banners, Facebook ads, and email marketing slowly lose impact on customers because of the immense amount of advertising surrounding us all. To make a true and sincere connection with your customers, and making them a loyal lover of your product and/or service it can be a way of staying closer to your customers, and being just a “fingertip” away at all times.

Conclusion

A mobile app can thus make things simpler for your members of any kind of community. A feature-rich mobile app with incredible performance can help you to attract your members. Therefore, it’s time you think about having a mobile app for your community and take action in that direction asap. There are a lot of mobile apps available in the market that can fit  your app like  SocialAPI-connect,communicate,collaborate , YouNet , SocialEngine Mobile App based on the different framework like Socialengine , BuddyPress , Oxwall, phpFox etc.

Performance optimization tips for SocialEngine and Phpfox in 2018

Are you fed up with performance issues on your website? Try these performance optimization tips right into the hosting to give the boost to social communities. Yahoo reported a 9% increase in traffic for every 400-millisecond increase in performance. Walmart experienced a 2% increase in conversions for every 1-second improvement in performance.  Amazon experienced a 1% increase in revenue for every 100 ms increase in performance. Google, the behemoth as it is in providing you with visibility, also ranks your website according to its speed. What does this tell us?  The faster your community is, the faster it will grow!

Now when you run a social networking platform or any other framework for that matter. It would run perfectly fine when the number of users is less. As you would grow your website becomes sluggish. At this point, each platform requires performance optimisation. There are several techniques to do this. There are many variety of tools – choosing which ones are going to work wonders for you, is tricky. Being around in this area for several years, we have used and continue to study and experiment with various approaches. Following are some of the techniques that have worked for a significant percentage of our Social Engine/Phpfox customers.

PHP Performance Optimization

PHP Performance Optimization

  • Realpath PHP cache settings are increased
  • PHP open_basedir is disabled for increased PHP performance
  • PHP-FPM (FastCGI Process Manager) is an alternative high-performance method of running PHP based web applications
  • Alternative PHP Cache (APC) is enabled and optimized for SocialEngine.

Web Server Performance Optimization

  • Keep-Alives are enabled with suitable values based on traffic from Google Analytics
  • Gzip output compression is enabled
  • Installing plugins for javascript and CSS compression
  • Using reverse proxy for caching static resources

Database Performance Optimization

  • Alternative engines of MySQL for better Socialegine performance
  • Database configuration based on what works best for SocialEngine
  • Scripts for optimizing indexes of tables most used

Custom Optimization

  • Profiling database queries and improves the most used ones
  • Improvements in plugins that may be slowing your site down or using alternative ones

It is possible to do all of this by yourself or getting developers to do this. However, in our experience, the community owners are really more focused on making their community an engaging experience via functionality or graphics. Similarly, most developers can write PHP code, but very few have the experience of various tools for improving performance. One of the solutions we thought was to bake this optimization right into the hosting. So we have teamed up with Acenet hosting to provide you hosting for SocialEngine and Phpfox. Which associated with built-in PHP, web server and database performance enhancements. Custom optimization may be required when your community grows huge, but that is different for everyone. We will continue to provide it as a separate service.

Please feel free to add your choice of recommendations and tools you feel have re-powered your social community performance in the comments below. We would certainly love to add them into the list for our readers.

References

Further Readings

Portfolio Items