Backend

Server side programming. LAMP Stack, NodeJS, CodeIgniter and more.

Laravel Sanctum optional route authentication and guard selection

Posted by Danny Herran on Jan 18, 2022 in Backend | No comments
Laravel Sanctum Logo

By default, Laravel Sanctum token authentication will either completely block access to protected routes or allow it at the expense of not being able to detect if the user is logged in. However, there are valid scenarios whereby a route should be accessible to guests and at the same time allow bearer token authentication. One of the many ways to achieve this is by changing the default guard assigned to the /api route group.

Laravel reCAPTCHA v2 Middleware in 3 minutes

Posted by Danny Herran on Nov 5, 2020 in Backend | No comments
Laravel reCAPTCHA

I needed to add reCAPTCHA v2 to a couple of forms and most of the results on Google pointed to these large Composer packages that were simply too much.

This article will cover how to do create a new Laravel Middleware to validate reCAPTCHA v2 requests with just a few lines of code.

Time to read, implement, QA and deploy to production: 3.141592 minutes.

Laravel Fractal pagination with simplePaginate

Posted by Danny Herran on Mar 8, 2019 in Backend | No comments
Laravel Fractal

By default Fractal has native support for Laravel::paginate. Those using simplePaginate() have to resort to either using Fractal Cursors or build their own adapter. In this post, we are going to quickly build an adapter that fully supports Laravel::simplePaginate.

This is how you upgrade (or downgrade) the PHP version on EasyPHP for Windows

Posted by Danny Herran on Nov 18, 2015 in Backend | 2 comments

easyphp-custom-php-version
Since August 2015, the EasyPHP developers have moved their modules into a called “Warehouse” in which they will host up to date modules for their famous WAMP server. This Warehouse is now subscription based, and if you want to download a module, say, the latest or an old PHP version, you will need to pay for it.

EasyPHP will remain free, is just the modules for customisation that are now under the subscription model. However, if you only want to update your PHP version to any in specific, just follow the steps below.

Seamlessly validate forms and file uploads with CodeIgniter

Posted by Danny Herran on Jul 12, 2014 in Backend | No comments

Form Validation CodeIgniter

The Form Validation class is great to validate simple input fields such as textareas, checkboxes, text fields, etc. But what about file inputs? If you have a mix of text and file inputs, your controller can get messy if you try to validate both. Lets take a look at a neat solution that only involves extending your Form Validation class.

How to load and use SimplePie 1.3+ with CodeIgniter 2.1+

Posted by Danny Herran on Jun 18, 2013 in Backend | 3 comments

SimplePie RSS CodeIgniter

The famous RSS parser, SimplePie, has changed a few rules in the last couple of versions. The previous methods used to install the library in CodeIgniter are now obsolete. Lets take a look at the new method to get it working in just 5 minutes.

How to force a cache refresh on CSS and JavaScript files with PHP?

Posted by Danny Herran on Dec 30, 2012 in Backend, Frontend | 1 comment

cache-internet-explorer-ie

There is your client, complaining that they can’t see the changes you just made to their website. You explain them that they need to delete their browser cache in order to properly visualize the modifications. They said they don’t know how, and this is when you lose your patience and decide for a more radical solution. We are developers right? there has to be something easier than explaining the client how to delete their cache. Read on for more.

Mobile browser detection for WordPress – embedded is_mobile() function

Posted by Danny Herran on Mar 7, 2012 in Backend | 5 comments

Lets face it. Responsive design is here to stay and it is the solution to all of our nightmares regarding mobile web design. For those who are not aware of this technique, I invite you to read my other post where I explain what it is. But lets get to the point. Sometimes we need to add conditionals to our WordPress theme in order to detect if the visitor is visiting us from a mobile device, if so, we remove or add content. This is solved by using a custom made function called is_mobile() embedded into our functions.php. Read on for more.

Finding unique array combinations with PHP (permutations)

Posted by Danny Herran on Jun 23, 2011 in Backend | 6 comments

I was developing a website where people would place horse bets and the system should be able to calculate all the possible permutations based on the user selection. That means: finding all the possible combinations in a two dimensional array. I found a couple of functions but none of them would keep the array keys intact. So, I came up with this idea after a few gray hairs.

Error Validation Class for CodeIgniter Reactor 2.0

Posted by Danny Herran on May 3, 2011 in Backend | 3 comments

CodeIgniter Error Validation Class CodeIgniter lacks of an error handling class for custom errors. The Form Validation class is very nice for forms, the logs are pretty useful as well, but what happens when we need to handle our own errors?. Currently there is no official solution for this so I decided to take the matter in my own hands.

I present you the Error Validation Class.

Exporting your MySQL table data with PHPExcel + CodeIgniter

Posted by Danny Herran on Mar 8, 2011 in Backend | 33 comments

PHPExcel + CodeIgniter Most of the time my clients need to download data from their database tables. Exporting to CSV is a pain in the rear for users and it leads to confusion (you know the colon and semicolon stuff). Today, I decided to make a very small controller that is portable and efficient for exporting full MySQL tables to Excel 2003 using PHPExcel and CodeIgniter.

Facebook PHP SDK and CodeIgniter for basic user authentication

Posted by Danny Herran on Feb 24, 2011 in Backend | 211 comments


With CodeIgniter 2, plugins are no longer an option. Usually you would just add the Facebook PHP SDK as a plugin and you were good to go, but now, you need to make a little modification to the SDK in order to use Facebook Connect on your CodeIgniter application. Lets start by explaining what is, how to get started and how to authenticate an user using the Facebook API.

CodeIgniter 2.0 is out with cool features!

Posted by Danny Herran on Feb 13, 2011 in Backend | 4 comments

I know its a bit late, CI 2.0 has been out since January 28th, 2011, but lets talk about it anyway and recapitulate some of the new features of this framework. The new stuff is great, and this time I believe it deserves a second look if you are not much into CI.

Let me thank in advance the guys of the CI team for their great work.

Read Word documents with PHP (up to Word 2003)

Posted by Danny Herran on Feb 10, 2011 in Backend | 8 comments

Reading Word documents with PHP on a Linux box can be a real pain. It requires DOM which is only available on the Windows platform. However, Unkwntech from Stack Overflow made quite a nice function to read Word documents and extract its information. It will only parse text content, but it is enough for most of the tasks we will be doing anyway.