Tag Archives: XHTML


Energy Saving Experts

March 16th, 2011 by

Energy Saving Experts Website - By Robert Heck

Client: Thomas McCarthy
Website: http://energysaving-experts.com
Site Features:

  • XHTML Coding
  • PHP/Javascript Contact Form
  • CSS Styling
  • Embeded Videos
  • Shopping Cart

Info: A Website and Shopping Cart I built a few weeks ago for a Client of Business Development Institute. The Content and products were provided by the client.


Tutorial – Add a User Agreement Message to your WordPress

March 14th, 2011 by

This will allow you to require your visitors to accept your User Agreement Terms with this little bit of code. This is great if you want to put a disclaimer, copyright notice, age required notice, or even adult content warning. The code is fairly simple and easy to implement, you will be adding it to your loop file(s) in your theme. Instead of showing you the code in one snippet I will be breaking it up into two because there is a part that goes at the top of the loop and the other part will go at the bottom.

Put this at the very top of your loop file(s)

  1. <?php
  2. session_start();
  3. if(!isset($_SESSION['grant_access'])) {
  4.         $_SESSION['grant_access'] = ‘unset’;
  5. }
  6. if(isset($_POST['agree'])) {
  7.         $_SESSION['grant_access'] = ‘set’;
  8. }
  9. if($_SESSION['grant_access'] == ‘unset’) {
  10. ?>
  11.         <h1>You don’t have Access to this content.</h1>
  12.         <h2>You must click the I Agree button to view this content.</h2>
  13.         <form method="post">
  14.                 <input type="submit" value="I Agree" name="agree" />
  15.         </form>
  16. <?php
  17. } else {
  18. ?>

Put this at the very bottom of your loop file(s)

  1. <?php } ?>

Here is what a very basic loop.php file would look like with the added code.

  1. <?php
  2. session_start();
  3. if(!isset($_SESSION['grant_access'])) {
  4.         $_SESSION['grant_access'] = ‘unset’;
  5. }
  6. if(isset($_POST['agree'])) {
  7.         $_SESSION['grant_access'] = ‘set’;
  8. }
  9. if($_SESSION['grant_access'] == ‘unset’) {
  10. ?>
  11.         <h1>You don’t have Access to this content.</h1>
  12.         <h2>You must click the I Agree button to view this content.</h2>
  13.         <form method="post">
  14.                 <input type="submit" value="I Agree" name="agree" />
  15.         </form>
  16. <?php
  17. } else {
  18. ?>
  19. <?php
  20. if (have_posts()) :
  21.    while (have_posts()) :
  22.       the_post();
  23.       the_content();
  24.    endwhile;
  25. endif;
  26. ?>
  27. <?php } ?>

Now that you have both parts that will be needed lets break it down a little bit further.

  1. <?php
  2. session_start();
  3. if(!isset($_SESSION['grant_access'])) {
  4.         $_SESSION['grant_access'] = ‘unset’;
  5. }

This part of the code is doing two things, first it is telling server to start a session which essentially means it allows your code to use and check for temporarily set cookies. These cookies will only stay on your computer until you close the browser you’re using. This is great for making sure the person who clicked accept is the one viewing your website since once they close the window the cookie will disappear.

The second part is checking if the cookie grant_access has not been set, if it hasn’t then we say it has a value of unset. We need to do this because by default cookies aren’t set until the page is reloaded. On to the next part of the code:

  1. if(isset($_POST['agree'])) {
  2.         $_SESSION['grant_access'] = ‘set’;
  3. }

This is a checking to see if the button “I agree” has been pressed and in turn posted its value. Once the button has been pressed/posted it changes the value of the temp cookie grant_access to set instead of unset. Now onto the third check:

  1. if($_SESSION['grant_access'] == ‘unset’) {
  2. ?>
  3.         <h1>You don’t have Access to this content.</h1>
  4.         <h2>You must click the I Agree button to view this content.</h2>
  5.         <form method="post">
  6.                 <input type="submit" value="I Agree" name="agree" />
  7.         </form>
  8. <?php
  9. } else {
  10. ?>

This part of the code is checking to see if the temp cookie grant_access value is unset. Remember the default value is unset as we defined it above. If it is then it spits out the little bit of HTML. If it value isn’t unset it will show the content as normal. Now for the last bit of the code:

  1. <?php } ?>

This is simply closing the else statement around the code that makes loop function once the user has clicked the I Agree button.

Note: If a user doesn’t have cookies enabled for whatever reason then this message will reappear on every page/post they try to visit as the temporary cookie being set isn’t saving due to cookies being disabled.


Survey Data Stored to mySQL Database

February 3rd, 2011 by

I was asked to build a survey form that would store the data to a database as well as read the data and convert it to understandable information in a results page. This is a stripped down version of the form that I built for whopeesintheshower.com. It connects with a mySQL database on my servers. It grabs the current integers stored in the respective fields and then increments the respective integer based on which options are filled out on the form.


Exposure Photography Splash Page

January 31st, 2011 by

Exposure Photography Splash Page - By Robert Heck

Client Friend: Jason Talley
Website: http://www.exposurebyjtalley.com
Site Features:

Info: Jason had done my engagement photos and then wedding photos and since then we’ve talked off and on about SEO help he needed as well as web advise. He came to me wanting to get a splash page to link his blog, online portfolio(still pending), and client photos. At first it was going to be just basic HTML/CSS but after shooting around some of my “wouldn’t it be cool” ideas we agreed on some PHP to help make the splash page easier for Jason to update images as well as keep the code on the website changing a little bit for SEO purposes. After a few issues with hosting and domain changes as well as some issues where I couldn’t see the site to make some final changes but it is finally up.


Tutorial – Pull in a Random Image from a Folder with PHP

January 18th, 2011 by

I came up with an idea for a client where instead of just pulling in the newest image in a file my code would pull in a random image from a folder. This serves two purposes:
1) Gives visitors the feeling of a page that gets updated and gives them something different to look at when they visit the website again.
2) It also changes the code which shows the page as being updated to spiders and other search engine bots. (To what degree this will help your SEO remains to be seen but likely on par with doing minor updates to your website)

Now how to get this done? Well I looked around and there were a lot of different ways to code it some from using things as simple as echoing an image name with a random number genrator attached to the end of the file name before the extension for example:

  1. <img src="image/filename_<?php echo rand(0, 2); ?>.jpg" alt="" />

To things that would be much more in depth and involved 20+ lines of code. The problem with all the code I found is that they were limited by having to define the file type and/or manually define how many images were in the folder.

Now here’s what I came up with for my random image generator:

  1. <?php
  2. $dir = ‘images/’;
  3. $images = scandir($dir);
  4. $i = rand(2, sizeof($images)-1);
  5. ?>
  6. <img src="images/<?php echo $images[$i]; ?>" alt="" />

That’s all the code I needed… 6 lines of code. This code scans a directory, generates a random number with a maximum set by the amount of files in directory. Then it prints out an image within the defined directory. This allows you to add as many or as few images to the folder as you want without ever changing the code.

Lets break it down:

  1. <?php
  2. $dir = ‘images/’;
  3. $images = scandir($dir);

This first section is doing 2 things:
1) Defines the directory for the images.
2) Creates an array of the defined directory.

Now that we have the files defined in an array lets create a random number generator:

  1. $i = rand(2, sizeof($images)-1);

This line of code is doing 3 things:
1) The obvious part is it generates a random number with rand.
2) We’re restricting it to start at 2 because 0 and 1 are always the directories (0 = ‘.’ and 1 = ‘..’)
3) We’re restricting the maximum number to the number of the array and subtract 1 from that to account for the fact that the array itself starts at 0, while the code”sizeof()” starts counting with 1 instead of 0.

The last part of the code is what will actually be visible in the HTML/XHTML:

  1. <img src="images/<?php echo $images[$i]; ?>" alt="" />

This is spitting out the file name that was randomly picked from the array using the random number we generated.

Update: You could even make the alt tag spit out the name of the file by changing the last line to this:

  1. <img src="images/<?php echo $images[$i]; ?>" alt="<?php echo str_replace(array(‘.jpg’, ‘.png’, ‘.gif’), ”, $images[$i]); ?>" />

This is simply replacing the possible file extensions with nothing so that the alt tag will say “filename” instead of “filename.jpg”.


Wealth 4 Life Global Enterprises Inc.

January 13th, 2011 by

Wealth 4 Life Global Enterprises Inc. designed by Robert Heck
Client: William Byron Austin
Website: http://incomegeneratingideas.com
Site Features:

  • XHTML Coding
  • PHP/Javascript Contact Form
  • CSS Styling
  • Flash/jQuery MP3 Player
  • Youtube Video
  • W3C Valid Coding

Info: A splash page that I built for a client of Business Development Institute. The Content was provided by the client.