Many religious or spiritually-oriented websites feature a “Daily Bible Verse" section. Each day new or returning visitors to the website see a new, inspiring bible verse. A web developer seeking to add such a feature can choose from a number of such widgets available on the web. Most such tools are free and high quality. This tutorial will help the web developer create his own "Daily Bible Verse" widget with just a few lines of programming.
Why Program a "Daily Bible Verse" Widget From Scratch?
Why would a web developer want to create his own "Daily Bible Verse" widget? There are a number of problems with using tools produced and provided by someone else:
- The person or organization offering the application may go out of business.
- Newer versions of the application may introduce unexpected incompatibilities.
- Foreign code may be a security risk to his web server.
- The developer has little or no control over what may be displayed on his website or how it is displayed.
It is possible for the web developer produce a simple, fast, safe, and free Daily Bible Verse widget for his website. The only tools he would need are a bible, a text editor or a webpage editor capable of saving HTML code as pure text. and a web hosting service which allows PHP scripting.
An Explanation of the PHP Code
Here is the how the "Daily Bible Verse" program will work: the program will ask operating system for the day of the year, a number from 0 through 365 (counting a leap year). The program will then search for, open up, and display the contents of a file corresponding to the day number.
Here is the code below
- < ? php
- $today = getdate();
- $day='v'.$today['yday'];
- echo file_get_contents('verses/'.$day);
- ? >
Line 1: this tag tells the web server to expect some php code
Line 2: this line gets today’s date
Line 3: here we get the numerical day of the year. and attach it to the letter v for example, if to day is the 190th day of the year, the file name would be “v190“
Line 4: this line reads the file from the disk and displays it
Line 5: this tag signals the end of php code
That's all there is to the actual program. The PHP code is placed into an appropriate part of the web page, wherever the Bible verse is to be displayed. The output of this program can be styled in any way the developer wishes.
Additional Files Needed by the "Daily Bible Verse" Web Application
The hard part comes in creating the individual verse files. The program requires one bible verse to be created per day of the year. The verses must be uploaded to and stored on the web server. Including leap years, the developer will need to create 366 files. Each file will contain a short verse like the one below:
"But I say unto you, That every idle word that men shall speak, they shall give account thereof in the day of judgment." Matthew 12:36
This is time consuming, but there are many advantages in a developer creating her own collection of scripture for her chosen audience:
- The developer has absolute control.
- She gets to pick her favorite scriptures.
- She can pick scripture based upon the seasons or holidays.
- She can use the Bible version of her choice.
- She can format the verses in a style consistent with the rest of her website.
The "Daily Bible Verse" widget in operation on the website Church Folk News. Give this easy to implement and customize widget a try.
Join the Conversation