Setup JWT for Laravel Lumen and AngularJS

So Laravel rewarded me for being an early adopter of their Micro-Framework Lumen by stripping it of Session and Cookie functionality, forcing me to rewrite code for several sites to use JWT authentication.

If you find yourself in the same spot, below is how is how I added JWT auth, of course in a very basic form as each site I am responsible for has custom integration.

JWT Front End Code

Using Satellizer - https://github.com/sahat/satellizer for AngularJS, the setup was pretty simple:

Update .htaccess

You may or may not have to do this, I did, so I am including it for you. This enables the "Bearer" JWT authentication token to pass through in each request.

Setup JWT Backend

Using composer I installed the PHP-JWT - https://github.com/firebase/php-jwt library.

Here is example code in the controller to check, parse, encode and decode JWT tokens.

Final Thoughts

If you need help or have questions please post them below, this took a bit of time to figure out, but once I did it was pretty easy simplify and replicate.

HTH

😉

UPDATE: Moving from CodeIgniter to Lumen

A while ago, I made the transition from CodeIgniter to Lumen and I wrote about it in a post about picking the right PHP framework for a SAAS membership site...

What I needed was a super lightweight and fast PHP framework to build out all of my MVP ( minimal viable product ) ideas, I chose Lumen by Laravel...

Little did I know HOW MUCH changing from CodeIgniter to Lumen would impact my server performance...

What happened next was CRAZY...

Below is an image of my server memory statistics the day that I pushed live the framework change from CodeIgniter to Lumen...

server-memory

The HUGE dip in memory usage was completely an unexpected performance boost... I figured that CodeIgniter was using a bit memory, I just didn't know the extent of the memory hogging that was going on...

Thinking perhaps this was a temporary thing, maybe the hosting company rebooted my server or somehow MySQL connections got reset...

How could Lumen really free up that much memory on my server right? Could CodeIgniter really be using that much of my total memory?

So I decided to wait a bit longer and then followed up with another screenshot that you can see below...

memory-statistics-2

About two days later, I took another screenshot of the memory statistics, the codebase now using Lumen by Laravel instead CodeIgniter showed just how much memory was NOW available...

Aside from some heavier cron jobs run in the early hours, most of the day is pretty steady now using Lumen as the PHP framework...

Just to be sure... I took another screenshot this morning of current memory usage, that's three months later and the screenshot is almost an exact duplicate of three months ago...

NOTE: I actually squeezed out slightly more memory with some code changes, so there is a bit MORE memory now available than three months ago!

memory-statistics-3

Steady and much faster with more memory available to handle sudden spikes... Very happy with Lumen from Laravel and would recommend it to anyone looking to build their next PHP project...

Before you upgrade your server...

Take a look at your framework... I know it's a pain to think of migrating to a new framework, the cost and time involved is nothing to take lightly, especially with larger projects that require code and content migration...

Year over year, you could actually benefit your business if you take the hit now and move to a framework that would enable you to use the money saved to re-invest into your business rather than handing it over to a hosting company for extra memory or servers...

Running lighter and leaner could end up providing a higher ROI when you take into account the cost of VPS or cloud hosting versus pumping that money back into your business...

It's easy to keep upgrading hosting, adding more memory or servers, even if you have deep pockets, eventually hosting fee's can get out of control...

But, when was the last time you looked at your codebase or framework? You could be leaking money and lot's of it!

How to find and delete inactive non-buying email subscribers on your aWeber account

If you use aWeber, you could be spending too much money every month...

With your hard work, eventually you will end up paying for the size of your list as it grows to 1000 then 10,000 and even 100,000+ emails...

Surprisingly, for many of you, a big chunk those email subscribers will never open your messages...

So why pay the extra money?

Here is how to find and remove the dead email subscribers from any of your aWeber lists...

Remove by Last Opened on aWeber

A rule of thumb for me is, if someone hasn't opened an email in a certain period of time, they get deleted from the list.

So how long do you wait? It depends on the sales cycle of your product or service, it could be three months, six months or a year, the idea is that you take a look to remove dead email addresses that cost you money every month.

STEP 1 Login into your aWeber account and in the navigation go to Subscribers then Manage Subscribers...

aWeber Manage Subscribers

STEP 2 In the search form, select the "No Opens" from the pulldown menu, then enter a date of your choice, I like to start with a year, after you have entered a date click the Search button.

The results...

Search Subscribers on aWeber

STEP 3 Scroll to the bottom of the page and click on the largest view available. This saves TONS of time in our next step by allowing us to select more records to delete at one time.

aWeber only allows you to select and delete records that are currently displayed, NOT in total. Since I have 800+ emails to delete, by selecting to view 100 records at a time, I would repeat this process about 8 to 9 times to delete all 800+ emails from my account.

Click largest subscriber view on aWeber

STEP 4 Scroll back up to the top of the screen, click the checkbox in the grey header area to select all 100 currently displayed records, then click the Delete button.

Select and remove subscribers from aWeber

STEP 5 Confirm you want to permanently delete the emails and that's it! Repeat these steps until you have removed all the email addresses who have not opened since the date you entered.

Confirm email delete on aWeber

Remove by Country on aWeber

Bottom line, some countries just don't buy, I don't ask why, I just know that certain countries do buy my products and services and others just don't...

So there is no sense of marketing a product or service to a country that will never buy, so those email subscribers need to get removed...

STEP 1 Login into your aWeber account and in the navigation go to Subscribers then Manage Subscribers...

aWeber Manage Subscribers

STEP 2 Select "Country (from IP)" from the pulldown, this sets a filter based on the country origin derived from the IP address of the email subscriber when they signed up...

Next, we select a NEGATIVE match using "is not" because we do not want to see results for countries that actually buy products and services...

Lastly, we type in the Country we do NOT want to delete email subscribers from, for example, I used United States, United Kingdom, Canada and Australia. Based on sales data, these countries consistently buy my products and services.

To add multiple countries, simply click on the green plus symbol.

If you are selling anything online, you should already have a pretty good idea WHERE in the world your customers are and what countries generate the bulk of your revenue.

Search for subscribers by country on aWeber

STEP 3 Scroll to the bottom and select the largest view, in my case it's 100. aWeber only allows you to delete records displayed, so in my example I have 1500+ emails to delete, I would only have to repeat this process 15 or so times versus deleting just 20 records at a time...

Click largest subscriber view on aWeber

STEP 4 Scroll back to the top of the page and click the checkbox in the grey header to select all displayed subscribers...

Then, click the "Delete" button...

Delete subscribers by country on aWeber

STEP 5 Confirm deletion of subscribers to premanently remove them from your list. Repeat steps 2 through 5 as needed to delete all subscribers that matched your search.

Confirm email delete on aWeber

It's not everyday...

Give your list a chance to grow, then check in on it and prune it as needed to keep it producing revenue.

At most, review your subscribers once a month, at the very least, every three months.

HTH

😉

How to use trello to generate targeted blog posts

Blogging is a great way to generate traffic to a new site or even increase traffic to an existing site...

Here is how to structure your blog using trello to maximize the attraction of visitors at all levels of interest.

You Need Structure

Blogging can get a bit out of control...

Because you can write about anything, most people do and end up creating an unfocused collection of articles that really doesn't translate into sales or new leads.

What you need is a simple structure to help you attract the audience you want exactly at the moment they are most interested and actively searching for you...

By using the structure below, it can help attract people at different levels of interest and teach them more of what they want.

The Example: Cooking Blog

Let's say I wanted to start a new cooking blog, with so much to cover, where would I start?

Using Trello, the first thing I would do is create lists, starting with the very basic concepts and moving from left to right getting into more advanced topics.

I would start with Safety and Sanitary posts, Knife Skills, on to Sauces then Simple Recipes...

Blogging Beginner to Advanced

The idea is to cover topics from beginners to advanced, from left to right, gradually increasing in complexity and progressing your readers to mastery...

I can use this also as the main navigation for my blog...

Visitors reading from left to right could self identify and choose where they feel their current skill set and interest match up...

Nobody really thinks of themselves as beginners, most everyone wants to try the advanced stuff but most people fall somewhere in the middle...

What To Write ???

Now that I have a few main topics, remember I can always add more, I can begin to fill in each main topic with blog post ideas...

Using a tool like Trello enables you to quickly capture ideas and re-arrange them, prioritize, collaborate, keep notes, attach files and so much more...

Planning Blog Posts

Really take time here and write down as many ideas on a main topic as possible...

If you get stuck, do searches for your main topic and find related blogs who have covered similar topics for ideas...

Looking at the example above, I was able to create twelve blog post ideas rather quickly, here is why...

1.) It's much easier to come up with three ideas per topic, instead of just twelve ideas.

2.) I can easily multiply the blog posts ideas by adding a new main topic and thinking of three more ideas for each one...

Now I have more blog post ideas than I have time to write!!!

Build your Post with Research and Notes

Trello enables you to label, upload, create checklist and so much more than I could possibly cover in this post...

You can create lists of items you want to make sure you write about...

You can also create notes and save links to references you have found online...

Trello really helps you build up a strong base for a great blog post, keeping everything centralized and easily accessible...

Trello Blog Post Details

Extra Credit: Scheduling Posts

If you are using WordPress for your blogging, you can try a free plugin called WordPress Editorial Calendar...

Once you feel that you have built a solid blog post and it is ready to be written, you can begin to fill in your Editorial Calendar in WordPress to help keep you organized...

Editorial Plugin

Now you know what to write and when it's due!

Free Resources

I am sharing the example Cooking Blog trello board for you to get ideas for your own board...

I strongly encourage you to start your own free trello account...

If you have a WordPress blog then try the WordPress Editorial Calendar, it's free and it can help keep you organized!

If you have questions, feel free to post them in the comments below!

HTH
😉

How I fixed broken Twitter Card images generated from my WordPress posts

Why are my Twitter Card images not showing?

I looked everywhere, in the plugin, meta tags, api documents, until...

I found the one file to fix that was keeping my images from showing up in my Twitter Cards.



Twitter Card Validator

The first thing you need to know about is the Twitter Card Validator.

You have to make sure you site is white listed, mine was and that was not the problem, but it may be the first thing you should check!

All you do is put in a url from one of your WordPress blog posts to preview what your auto-generated Twitter Card will look like.

Twitter Card Validator - White Listed

Here is what my Twitter Card looked like, notice NO IMAGE!!! ARRRRGGG!!!

Twitter Card Validator - No Image

Making Sure Settings Are Correct

Using Yoast's WordPress SEO plugin, under the social settings I made sure I checked the "Add Twitter card meta data" checkbox and saved my changes.

Yoast SEO Twitter Card

Then I doubled checked that the meta tags are actually getting rendered in the head tag...

I thought that maybe I found the problem, maybe it was the Yoast WordPress SEO plugin using a meta tag with an extra ":src" on it?

Yoast Twitter Card Meta

Note: Twitter specifically says to use "twitter:image" mentioned in their Card Type docs, took a screenshot, see below...

Twitter Card Meta

So I tested using several different posts ( Twitter caches results once fetched for 7 days )...

In the /wp-content/plugins/wordpress-seo/frontend/class-twitter.php file starting on line 383, the code below contains a function called image_output...

Made the change, but still not getting images on my Twitter Cards...

The Fix... Damn Robots.txt !!!

The second part of the answer came when I stumbled across Twitter URL Crawling & Caching page.

Turns out I created a ROBOTS.TXT file a loooooong time ago and it blocks all crawlers from indexing just about everything except posts and pages...

That's a problem because Twitter wants to crawl and cache the image it is going to use in the Twitter Card for 7 days...

So I had to add special rules for "Twitterbot" to allow it to access the default WordPress uploads folder where all my images exist.

The first three lines did the trick, I am able to still block all other crawlers with the rules that appear below the first three lines.

User-agent: Twitterbot
Disallow: *
Allow: /wp-content/uploads/*

User-agent: *
Disallow: /wp-admin*
Disallow: /wp-login.php
Disallow: /wp-content*
Disallow: /*/feed
Disallow: /*/trackback
Disallow: /*?
Disallow: /*.js$
Disallow: /*.inc$
Disallow: /*.css$
Disallow: /category/
Disallow: /page/
Disallow: /pages/
Disallow: /feed/
Disallow: /feed
Disallow: /tag/
Disallow: /archives/

We Have Images!!!

With the ROBOTS.TXT file update, I am now able to generate Twitter Cards that contain images!


Summary Card


Twitter Card Validator - Summary


Summary Large Image Card


Twitter Card Validator - Summary Large Image

I still left the patch to the Yoast WordPress SEO plugin in my file to follow Twitter guidelines and will fire off an email to the Yoast development team.

For the record I did test with and without the plugin patch after the ROBOTS.txt file update and Twitter Card images showed in both instances.

Hope this helps!

Who is Cesar Serna?

Located in Southern California, I am a WordPress developer, iOS Game Developer and on rare occasion a Flamenco guitarist.