NoCatSplash With Authentication

DD-WRT is an open-source Wi-Fi firmware that you can install on select consumer-based wireless routers. I’ve been using the DD-WRT firmware on several Linksys and Buffalo wireless access points for a number of years. In addition, I have also implemented a feature called NoCatSplash.

NoCatSplash is a feature that allows wireless users to be redirected to a special splash page, whether to notify users of a disclaimer, or to make users agree to certain terms and agreement, or simply to advertise a web page. The NoCatSplash feature will prevent users with access to the Internet until they click on the submit button, thereby agreeing to the terms and agreement.

What was lacking with NoCatSplash was authentication. So, with a little bit of research, I found someone’s code at Github that allows simple authentication with NoCatSplash. It’s written in PHP and doesn’t require a database. It’s quite simple, but works flawlessly. The login credentials are kept on a file and can be changed anytime you’ll need to change passwords.

I’ve modified his code to fit my needs. Suffice to say, the code works great as advertised.

Fixing CodeIgniter Email Setup

I have been using an application I wrote in CodeIgniter that sends email notifications when an advertising link is activated or when it has expired. Several weeks ago, it suddenly stopped working. It was no longer sending email notifications as intended. I was using GMail’s SMTP server to send out the email notifications. GMail’s SMTP does require authentication. Typically, the CodeIgniter’s email preferences are located in the “config/email.php” file. It dawned on me that changing my GMail password broke my script. Here’s my email preferences found in the config/email.php file.

$config['protocol']='smtp';
$config['smtp_host']='ssl://smtp.gmail.com';
$config['smtp_port']='465';
$config['smtp_timeout']='30';
$config['smtp_user']='yourusername@gmail.com';
$config['smtp_pass']='your password';
$config['charset']='utf-8';
$config['newline']="\r\n";

So, updating the password fixed my problem.

Simple Invoices 500 Internal Server Error

Simple Invoices is a free, open source, web based invoicing system that you can install on your server, desktop, or at a service provider. I installed Simple Invoices on a webhost company I rather not mention. The application was working fine, until they tweak their PHP settings several months back. As a result, the PDF export in Simple Invoices no longer worked. I was bummed. So, I was forced to run Simple Invoices from my home server, which was fun, but the issue was, I can’t access it outside of the house.

So, I decided to install Simple Invoices on my new account at Linode. Now, the funny thing was, the application won’t even come up. Not even a login page. So, I searched online for a possible solution to my dilemma. Some suggested to increase the php memory settings to 128M, but that didn’t work out for me. At one time, I thought I had a missing pdo_mysql module, but that wasn’t the case. Then, I stumbled into something that led me to the ultimate discovery.

Simple Invoices has this configuration file called config.ini located inside the config folder. One thing this application doesn’t like are extra characters inside the config file. I happen to like funky passwords with interesting characters like +-)!@#. My MySQL password happens to have a close parenthesis in it. Essentially, this extra character caused the entire application to not start. So, I change my password, and sure enough, the application worked.

So, if you ever get a 500 internal server error with the Simple Invoices application, make sure you don’t have any of those extra characters inside your config.ini file. I wasted two hours trying to fix this issue, only to be surprised by such an idiotic requirement. That means I can’t use difficult passwords for this application. I think this is either a design issue or a funny requirement of the Zend Framework, which by the way, Simple Invoices is written on. It was somewhat funny, but I wasn’t amused.

WordPress Blank Dashboard

I recently moved one of my blogs to Linode, a VPS hosting company. I noticed right away, when I logged in as admin, that the WordPress Dashboard, displayed a blank page. That’s not good. So, I started removing plugins by renaming the plugin directories until I found the offending plugin. Sure enough, it was a custom plugin I wrote myself.

Nothing has changed. The plugin hasn’t been touch. WordPress is the same latest version. The only thing that changed was the host server. So, I started looking into my PHP installation. What could possibly be missing? When I looked into my plugin code, I noticed some references to curl. I realized my server was missing a php5-curl module on the new host server.

A simple command to install php5-curl on the new server does the trick.

sudo apt-get install php5-curl

In this particular case, a missing module in PHP, caused the plugin to die unexpectedly, resulting in a blank Dashboard page within WordPress. Removing offending plugins temporarily fixes the issue, but it doesn’t get to the root of the problem. In my case, I was able to narrow it down to the missing PHP curl module that my plugin desperately needs.

In any case, everything is back to normal as expected, except for the blog, which is serving pages exceptionally fast, since I’m now running at Linode.

PHPVirtualBox

PHPVirtualBox is a web-based program that allows you to control a remote Virtualbox GUI. PHPVirtualBox is ideal for systems that don’t have remote GUI access. Access is done via a browser. Remote virtual machines can be started and stopped, shutdown, and rebooted. In addition, snapshots can be taken, deleted and restored remotely via the browser. Howtoforge.com goes over the installation of PHPVirtualbox in this short article.

CodeIgniter Form_Dropdown

I had a little problem using CodeIgniter’s form_dropdown the other day. Form_dropdown produces an output similar to HTML’s form select option. I was trying to retrieve data queried from a database and display the result in a form. Well, after several test and trials, I finally got the script to work. Here’s how I did it.

Form_Dropdown

The form_dropdown function typically has 3 options. The first option is the fieldname. The second option is the option data usually laid out in an array. The third is the selected data.

form_dropdown(‘name’, array(1?=>’one’,2?=>’two’,3?=>’three’),1);

This produces:

<select name=’name’>
<option value=”1? selected=”selected”>One</option>
<option value=”2?>Two</option>
<option value=”3?>Three</option>
</select>

CodeIgniter

In CodeIgniter, I have a simple script that stores bookmarks. I categorize my bookmarks using tags. When adding bookmarks, I call on the get_dropdown_tags function in Models to retrieve all the tags and display them in array that I can use with form_dropdown. Here are my CodeIgniter entries.

Controller:

$data['tags'] = $this-&gt;links_model-&gt;get_dropdown_tags();

Models:

function get_dropdown_tags() {
  $tags = $this-&gt;db-&gt;query('select distinct tag from links');
  $dropdowns = $tags-&gt;result();
  foreach ($dropdowns as $dropdown) {
    $dropdownlist[$dropdown-&gt;tag] = $dropdown-&gt;tag;
  }
  $finaldropdown = $dropdownlist;
  return $finaldropdown;
}

Views:

In views, I’m simply calling the form_dropdown function using the $tags array passed on by the controller. It’s a pretty neat way to recall data from a database and outputting them in form_dropdown.

<?=form_dropdown(‘tag’,$tags);?>

Finally, a dropdown list that works.

Aptana Studio 3

I finally took the plunge and downloaded Aptana Studio 3. Aptana is an open-source IDE or integrated development environment for web developers. The IDE supports all the latest web technologies including HTML5, CSS3, JavaScript, Ruby, Rails, PHP and Python.

It’s impressive despite having only a couple of hours playing with it. I really like the ‘code assist’ feature that comes with the IDE. I haven’t use all the features yet, but the deployment wizard, git integration, and the built-in terminal, sounds very, very inviting.

The learning curve isn’t steep. It’s just the right level for someone who may be tempted to try using an IDE. Aptana reminds me of Eclipse and a little bit of Textmate. The program does require Java, which my Ubuntu desktop already has installed.

Some people had issues with Git commits and some complaints about the program being resource hungry. I can’t comment on those yet since I’ve only been using it for a couple of hours. My first impression of Aptana Studio 3 is very good.

Str_replace

The str_replace function in PHP, is similar to the find and replace function that you’ll find in most text editors. Microsoft Word, Google Docs, Notepad, WordPad, Gedit, and a gaggle of other text editors, all have the find and replace function. It’s a very neat feature that comes in very handy when doing wholesale changes to a document.

In PHP, I use the str_replace function mostly to filter unwanted characters, like commas, quotes, etc from a certain string. The string can originate from a form or database. It doesn’t really matter. In this example, I have a string called $a. I will use the str_replace function to search for a word ‘foo’ and replace it with the word ‘bar.’

Replace Foo With Bar

$a = 'foo, is a great word.';
$b = str_replace('foo', 'bar', $a);
echo $b;

The result: ‘bar, is a great word.’

Remove Commas

$a = 'foo, is a great word.';
echo $b = str_replace(',', ' ', $a);

The result: ‘foo is a great word.’

Notice I used a shortcut to echo the string $b, while assigning to it the str_replace function. You can use str_replace to filter and replace a character, a word or a group of words from within a string.

Remove index.php in Codeigniter

If you work with CodeIgniter, you will soon learn fast enough that the CodeIgniter framework, by default, uses the index.php in its URL. Here’s an example of how the URL would look like with the index.php being visible.

CodeIgniter URL

http://example.com/index.php/news/article/my_article

.htaccess

To remove the index.php from the URL, you will need to add mod rewrite rules to the .htaccess file in your main CodeIgniter directory. Use this code. Change the rewrite base to your own settings.

&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /ci/
 
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
 
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
&lt;/IfModule&gt;
 
&lt;IfModule !mod_rewrite.c&gt;
ErrorDocument 404 /index.php
&lt;/IfModule&gt;

config.php

In addition, you will need to edit the /application/config/config.php file. Make sure to remove index.php reference within the file.

$config['index_page'] = '';

Adding Javascript Confirmation To Forms

One feature worth implementing when designing websites is to add confirmation to forms. A simple popup message saying “Are you sure?” can greatly enhanced the user experience. It gives users a chance to confirm or escape out of a certain function. This is particularly feature is valuable after users click the Save, Delete or Submit button.

Unfortunately, both HTML and PHP languages lack the feature to add confirmation to forms. We turn our attention to Javascript the popup confirmation message we need in our forms. Below, you will see a simple, plain vanilla, submit button inside a HTML form.

HTML Form

<input type="Submit" name="submit" value="Submit" />

To add a confirmation to our submit button, we will use Javascript’s onclick event to detect if the input object has been clicked. Here’s how we add the onclick event in our simple form.

<input type="Submit" name="submit" value="Submit"
onclick="return confirmation();" />

Javascript Confirmation

Where’s our Javascript function? Well, here it is. Now that we have added the onclick event to our submit button, we will now add our Javascript function that you can place anywhere on your page. Here it is:

<script>
function confirmation()
{
var answer = confirm("Are you sure?")
 if (answer)
 {
  return true;
 } else {
  if (window.event) // True with IE, false with other browsers
  {
   window.event.returnValue=false; //IE specific
  } else {
   return false
  }
 }
}
</script>

The if statement with window.event is for the IE browser since it doesn’t play nice like the other browsers. You can call the Javascript function multiple times on the same page every time you need a popup confirmation. So there you have it, a simple popup confirmation you can add to your forms.