Password Protecting Pages With GoDaddy, PHP and mySQL

I host several domains with GoDaddy, and while they offer cheap prices, they also offer cheap service and features. Last week I needed to password protect some content. First, I tried to protect folders with htaccess and htpasswd files, but I could not get it to work. Several forums suggested GoDaddy hosting is not compatible with htaccess, so I went with the PHP-mySQL route instead. (note: here is a tutorial from GoDaddy for automating the htaccess process, which looks less-professional than the PHP solution because of the htaccess’s popup dialog box: GoDaddy Instructions). Credit to Ethan Nordness for the PHP code.

Step 1: Create a new mySQL Database

GoDaddy hosting gives you access to 10 mySQL servers for free with your account. Log into GoDaddy, click on Hosting, then Manage Account. Select Databases and click on MySQL. Then in the nav bar, Create Database. Be sure to save your record your database name, password, etc, as you will be using them later. Once your database is set up, click on Manage via phpMyAdmin. First, create a new table in your database. Then, add 4 fields with the following properties (leave all other properties as they are):


Field ## Type ## Length/Values ## Collation
uid ## int ## 30
username ## varchar ## 30 ## utf8_general_ci
password ## varchar ## 50 ## utf8_general_ci
creation ## varchar ## 30 ## utf8_general_ci

Step 2: Create User(s)

Select the table you made and click on the “Insert” tab at the top of the page. It is important that the Uid field is given a unique value. Passwords are case sensitive, Usernames are not, and Creation is for your own use/reference.

Step 3: Implement Code

The 3 code files are stored at .txt files for ease of making them available on the web, but all 3 should be .php files in your implementation.

login.php When users go to a page that implements the password protection, they are redirected here. Keep in mind that All the pages should/can be customized with HTML to match your website’s theme and layout.

Go To login.txt

auth.php The filename of this PHP file can be changed. For example, in our implementation, we call this file index.php so our users do not see the file name in the URL. Simply copy this bit of code to the top of any page you want password-protected and save the file as .php. Through initial testing, the password-protected pages need to be in sub folders of the location of the login.php file (or they could be in the same folder).

Go To auth.txt

logout.php Direct users to this page to end their current session.

Go To logout.txt

Further, tracking logins requires only a small code tweak, discussed here

Enjoy!

3 Legged Bicycle

two people on a tandem bike with only 3 legs; two in front, one in back

I saw the most bizarre thing on Saturday while we were eating lunch on HWY 101 after some surfing. Luckily we were able to get out of the restaurant and catch up to the speedsters to snap this pic. If you look closely, the lady has a prosthetic leg, but the best part is she keeps it in the surfboard rack on the bicycle! Also, the fact that her running shoe is laced up and ready to go is just grand.

Facebook Badge Does Not Update

I tried adding the “Facebook Badge” to my website (get it by editing the websites of your contact details of your Facebook profile — warning: not advisable) but the information does not update automatically. What good is a “badge” that shows your current status and most recently uploaded pictures if it does not update? Come on Facebook, you’re better than this. If I wanted a time capsule I would have buried a box in the dirt. If I wanted a cool “badge”… apparently I would have had to make it myself. Facebook Badge: delete.