PHP code to create an online tour of website pages

I felt like doing some programming today.  So, I decided to add an online tour to one of my websites, www.XwayXway.com, which is a geo-domain about Stanley Park in Vancouver, B.C., Canada.  I wanted to have links on every .html page that the user can click on to view all the pages of the web site in a particular order.

I decided to do this task using PHP so I didn’t have to duplicate code in every .html file and it would be easier to maintain having one file with the order of all the .html files.  Also,  I had already enabled PHP for my websites on my web host so it was available to use.

First, I created a PHP file called: PHP_StanleyParkTourBottom.php

First, to make it generic, I needed to determine what .html page the user was on:

//get the webpage name, e.g. index.html

$url = $_SERVER[‘REQUEST_URI’];
//strip off the first backslash
$url = trim(str_replace(“/”,””,$url));
//make it uppercase
$url = strtoupper($url);
//echo $url;

This involved a call to the server.  I also stripped off the leading “/” and made it uppercase.

Next, I needed to handle the main webpage to start the tuturial:

//main page may be index.html or blank
if ($url == “INDEX.HTML” or $url == “”)
{
//create the table for the main web page
echo “<!–NAVIGATION–>”;
echo “<p id=\”StanleyParkTourBottomHeading\”>”;
echo “Stanley Park Tour”;
echo “</p>”;
echo “<table id=\”tblStanleyParkTourBottom\”>”;
echo “<tr>”;
echo “<td class=\”tdStanleyParkTourBottom\”><a href=\”XwayXway_Stanley_Park_Tours.html\”>Click Here to Start Free Online Tour of Stanley Park</a></td>”;
echo “</tr>”;
echo “</table>”;
echo “<!–NAVIGATION-END–>”;
}

I decided to use a table.  What you don’t see here is the CSS to make a thick border around the “Click here…” part to make it stand out.  I used “echo” statements to produce the HTML code.  It was a little tricky getting the double-quotes correct.  Remember you have to use \” to do a literal double-quote.

Then, I needed to handle the other .html webpages:

else
{
//first get the previous and next page urls
switch ($url)
{
case “XWAYXWAY_STANLEY_PARK_TOURS.HTML”:
$urlPrevious = “index.html”;
$urlNext = “XwayXway_Stanley_Park_Horse_Drawn_Tours.html”;
break;
case “XWAYXWAY_STANLEY_PARK_HORSE_DRAWN_TOURS.HTML”:
$urlPrevious = “XwayXway_Stanley_Park_Tours.html”;
$urlNext = “XwayXway_Stanley_Park_Aerodynamic_Forms_In_Space_Art.html”;
break;

…   about 100 more cases …

default:
$urlPrevious = “”;
$urlNext = “”;
}

I decided to use a switch statement within the PHP.  I could have created a MySql database and table, but decided that would be overkill.  The switch statement contained the html pages that are on the website.  For each one, the previous and next html pages were defined.  There were some pages that I didn’t want in the tour.  These pages will default to no previous and next page.

Then, I needed to create the tables with the specific previous and next values:

if (!($urlPrevious == “” and $urlNext == “”))
{
//create the table for the current web page
echo “<!–NAVIGATION–>”;
echo “<p id=\”StanleyParkTourBottomHeading\”>”;
echo “Stanley Park Tour”;
echo “</p>”;
echo “<table id=\”tblStanleyParkTourBottom\”>”;
echo “<tr>”;
echo “<td class=\”tdStanleyParkTourBottom\”><a href=\”” . $urlPrevious . “\”>Previous</a></td>”;
echo “<td class=\”tdStanleyParkTourBottom\”><a href=\”” . $urlNext . “\”>Next</a></td>”;
echo “</tr>”;
echo “</table>”;
echo “<!–NAVIGATION-END–>”;
}

Later, I decided to add in a section for the pages that I didn’t include in the tour.  They would just have a link to start the tour similar to the main web page.
else
{
//create the table for the tour start for pages not in the tour
echo “<!–NAVIGATION–>”;
echo “<p id=\”StanleyParkTourBottomHeading\”>”;
echo “Stanley Park Tour”;
echo “</p>”;
echo “<table id=\”tblStanleyParkTourBottom\”>”;
echo “<tr>”;
echo “<td class=\”tdStanleyParkTourBottom\”><a href=\”XwayXway_Stanley_Park_Tours.html\”>Click Here to Start Free Online Tour of Stanley Park</a></td>”;
echo “</tr>”;
echo “</table>”;
echo “<!–NAVIGATION-END–>”;
}

Then, I needed to add the following PHP include statement to each of the 100+ html files on my website:

<?php include(‘PHP_StanleyParkTourBottom.php’); ?>

So, that completes  It was a little tedious adding in all the cases and adding the 1 line to over 100 files, but I am happy with the result.  I’m hoping that the tour will increase the page views and clicks on ads on www.XwayXway.com

How to change GoDaddy session timeout limit?

I use GoDaddy for my hosting.  Quite frequently, I will sign in to GoDaddy, uploaded some changed files, then test the changes, make updates, then re-upload the files.  I found that if I keep the FTP File Manager open, then I can continue to upload files without my session timing out.  However, if I go to do anything else in my account, I usually get a timeout message.  I don’t know for sure, but the timeout limit for GoDaddy seems to be around 15 minutes.  If you are on some GoDaddy screens it will pop-up a message saying that it is timing out and give you the option to extend your session.  Frequently though, I don’t see this pop-up and have to logon again.  The last time I called GoDaddy support, I asked if they could the timeout limit for me.  I was told that it was a global setting and that they could not raise the limit for me.  So, the answer is No, you cannot change the GoDaddy session timeout limit.

Can people see the source code of my PHP files on my web site?

On one of my web sites, I am using PHP as the server-side language to connect to a MySql database.  In order to connect to the database, you need to build a connection string that has a user id and password.  At first, I was really concerned that somebody would be able to just view the source of my PHP files and get my database user id and password.  I did some research and everybody says that it is impossible for somebody to see the PHP source code on a website.  Just to be safe, I used the FTP File Manager on my GoDaddy hosting to change the permissions of my PHP files to be execute only.   So, the answer to the question is ‘NO’, the source code of PHP files on a web site cannot be seen by web site users.

How to generate more traffic to website from YouTube videos

I am trying various methods to increase the traffic to my web sites.  One method is to put videos up on YouTube.  However, I found that my videos were not being viewed too frequently.  Then, I realized that you should update the ‘Basic Information’ about each video.  For example,

YouTube screen shot showing fields that can be optimized to generate more views and hence more traffic to your website
YouTube screen shot showing fields that you should optimize for each of your videos in order to increase views.

for my www.CustomTravelChecklist.com web site video, I  did the following:

  1. Updated the Category to ‘Travel and Events’.
  2. Added a ‘call to action’ at the end of the Description telling the user to ‘Go to’ my web site.
  3. Added Tags that seemed appropriate.  Just type in the word(s) that you want as Tags and press Tab.  Note that YouTube gives you suggested tags below the Tags field that you can just click on.

I’m hoping that these simple updates will generate more views of my videos and hopefully more views will generate more traffic to my web site.  I will report back later to let you know how well this worked!

 

How to get a second YouTube channel

One way that I use to generate traffic to my websites is to put up relevant videos on YouTube.  On my first website, I created a “channel” and added videos to this channel.  This channel linked to my gmail email.  For my second website, I wanted a new channel because I didn’t want to mix the videos of the two very different websites because the topics were very different.  I looked around in YouTube and realized that it didn’t allow you to have 2 channels for 1 user.  So, the workaround I found was to create a new 2nd gmail email account.  Then, using this gmail email, I was able to create a 2nd user and 2nd channel (http://www.youtube.com/user/customtravelchecklis) on YouTube.  Hopefully, one day YouTube will be changed to allow multiple channels for an email, otherwise I may end up with lots of gmail emails!

How to Add Google Analytics Tracking to a WordPress Blog

I use Google Analytics to track the activity of my websites.  I just created this blog and wasn’t sure how to set it up with Analytics.  I did research and it is pretty darn easy.  I went to http://wordpress.org/extend/plugins/google-analytics-for-wordpress/ which had instructions.  I downloaded the plug in from here to my computer.  After virus scanning it, I extracted the files.  It was actually a folder with a bunch of files in it.  I then went to my host, GoDaddy, and uploaded the entire folder to the wordpress plugins folder (as described in the instructions on the web page).  Then, I went into Google Analytics and added my website, www.LunaSystems.ca, to it.  Then, returning to my WordPress site,  I looked for the Plugin in ‘Plugins-Installed Plugins’ but the Google Analytics plug in wasn’t there.  I had to select ‘Plugins-Add New’, then Search for ‘Google Analytics’.  It brought back a list from which I selected the one that I had downloaded/uploaded earlier.  I selected it and installed/activated it.  It asked me for my tracking code.  I selected manual entry and had to enter the Tracking Id (not the code).  That was all it took and it seems to be working.  Adding Google Analytics to WordPress will let me track my blog activity along with the activity from my other websites.

Using Frames in your website hurts Search Engine Ranking

The biggest mistake that I made when developing some of my web sites was that I used frames in my html.  Using frames allowed my website (www.CustomTravelChecklist.com) to show multiple separate .html files on the screen at the same time.  I could easily switch the main .html file in the center to show different .html file.  Also, I was using javascript and stored session variables in a hidden .html file.  Technically, this worked well.  However, I came to realize that search engines did not properly index my website.  My ranking never seemed to go up.  I added a site map and submitted it to the search engines, but that didn’t seem to help too much either.  I then did some research on the internet to see if there was some specific SEO (Search Engine Optimization) that I could do for frames.  The general consensus was that there isn’t any SEO that would help.  I wish that I had known this before building the site.  I would have architected it differently.  So, if you develop a website, I recommend that you don’t use frames.

New Blog on Web Development, Social Media, and Domaining

As part of my ongoing professional development within Luna Systems Corporation, I have been dabbling in web development, social media, and domaining.  I will use this blog to share what I’ve learned, best practices, what work for me and especially what didn’t work!