Tag Archives: php

How to generate X-WSSE Token using PHP

Learn how to generate X-WSSE Token and how to authorize requests using X-WSSE header authentication.

If you’re not familiar with X-WSSE Token Authentication and why you should use it, go ahead and read this article that contains the basics of this type of authentication.

In this article I’ll describe how to generate a X-WSSE Token using PHP.

function getWsseHeader($username, $secret) {
 
    $nonce = md5(rand());
    $created  = date('c');
    $digest   = base64_encode(hash('sha256', $nonce . $created . $secret, false));
 
    $wsseHeader = sprintf(
        'UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"',
        $username,
        $digest,
        $nonce,
        $created
    );
 
    return $wsseHeader;
 
}
 
$xwsse = getWsseHeader("CLIENT_ID", "CLIENT_SECRET");
echo $xwsse;

That’s it. Check my other X-WSSE Articles and learn how to generate the token using other programming languages.

How to create a basic Google Maps plugin for WordPress

There might be some WordPress plugins out there that could be used to add Google map to posts and pages. Still I didn’t find it necessary to install one when creating it is fun and easy.

Adding the final plugin to a post/page will be done using shortcode.

First of all you must create the plugin directory in wp-content/plugins/plugin_name.

Add two files here, the first an empty index.php and the second plugin_name.php

In order to be able to activate this plugin some basic details need to be added at the beginning:

/**
 * Plugin Name: Custom Google Maps
 * Plugin URI: http://catalinmunteanu.com
 * Description: Create Google Map element using a location query
 * Version: 1.0.0
 * Author: Catalin Munteanu
 * Author URI: http://catalinmunteanu.com
 */

Then we must create a function that will process this plugin’s shortcode:

 

function google_map_print($attrs, $content=null) {
    $item = shortcode_atts(
        array(
            'location' => null
        ),
        $attrs,
        'google-map'
    );

    $result = '<div>';
        $result .= '<iframe
            width="100%"
            height="250"
            scrolling="no" marginheight="0" marginwidth="0"
            frameborder="0" style="border:0"
            src="https://maps.google.com/maps?f=q&hl=en&geocode=&q='.$item['location'].'&aq=t&ie=UTF8&hq=&t=m&z=17&output=embed">
            </iframe>';
    $result .= '</div>';
    return $result;

}

add_shortcode('google-map', 'google_map_print');

 

That’s all. After you activate the plugin you can add it in your posts and pages using the shortcode:

[google-map location="Bucharest"]

Result: