Tag Archives: HTML


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.


Serious Entrepreneur Website

February 1st, 2011 by

Serious Entrepreneurs Splash - By Robert Heck
Client: William Whearty
Website: http://lucrativeonlinepay.com
Site Features:

  • XHTML Coding
  • PHP/Javascript Contact Form
  • CSS Styling
  • W3C Valid Coding

Info: A splash page I built last week for a Client of Business Development Institute. The Content was provided by the client. Images were from my collection of royalty free images.


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 – Using Binary to Alternate Class/ID Names

January 6th, 2011 by

In this tutorial I will show you how to use a PHP check to test weather or not a number is odd or even. This will then be used to load different class/ID names so that different CSS can be applied. This is a great tool to alternate code that is being run through a loop, for example WordPress posts on the main page.

Here’s all the code that is needed:

  1. <?php $i = 0; ?>
  2. <!– Part 2 –>
  3. <?php $i++; ?>
  4.                 <div <?php if($i & 1) { echo ‘class="name01"’;} else {echo ‘class="name02"’;} ?>>

Now the first thing you’ll notice is I have the code separated into 2 parts. The reason for this is because the code will have to exist in 2 different parts.

  1. <?php $i = 0; ?>

This will set the default value for $i. It needs to go outside of your loop because if you were to put it into the loop you’d always reset the value.

Now lets look at the rest of the code that will inside of your loop:

  1. <?php $i++; ?>
  2.                 <div <?php if($i & 1) { echo ‘class="name01"’;} else {echo ‘class="name02"’;} ?>>

The first thing we’re doing is incrementing $i by one number, this will go up every time this is triggered by the loop. Lets say your loop runs 3 times then $i will go like this: 0 > 1 > 2 > 3.

Now the next line of code is comparing $i to 1 and then will give the div the class name based on weather or not the match is true. Now you’re probably thinking it will only work when $i is 1 but what it is doing is comparing the match in binary. Here’s what some of the numbers look like in binary:

0 = 00000000
1 = 00000001
2 = 00000010
3 = 00000011
4 = 00000100

what “$i & 1″ is actually looking for is if the 2 numbers in binary form ever have a matching number. So for 0 > 1 > 2 > 3 it would actually look like this:
0 & 1:
00000000
00000001
———-
No match

1 & 1:
00000001
00000001
———-
Match on last digit

2 & 1:
00000010
00000001
———-
No match

3 & 1:
00000011
00000001
———-
Match on last digit

So that is how it knows which number is odd and which one is even. And that is how you can make alternating class/ID names with PHP.


Kelley Pool Repair Inc. Business Website

December 21st, 2010 by

Kelley Pool Repair Inc. designed by Robert Heck

Client: Andy
Website:http://www.kprepair.com
Site Features:

  • XHTML Coding
  • PHP Coding
  • CSS Styling
  • WordPress CMS

Info:Andy came to me with the idea of building a website for the family business as a Christmas present to his father. I went over a couple of ideas with Andy and his sister until we came up with this final layout that they liked. After building the initial mock up in hand coded HTML/PHP/CSS Andy and his sister went over some features they wanted to have added which involved them being able to create/update/delete pages.

They wanted an easy way to do this without having to work around my schedule so I went over a few options and I decided to use WordPress for it. This way they had a simple and easy to use back-end that gave them the ability to create/update/delete posts as they needed and I even built each page through the WordPress back-end so they could change the text on them if they felt the need.