PHP Script Archive

About Isset()

According to PHP Isset is:

Determine if a variable is set and is not NULL.

If a variable has been unset with unset(), it will no longer be set. isset() will return FALSE if testing a variable that has been set to NULL. Also note that a NULL byte (“\0”) is not equivalent to the PHP NULL constant.

If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are set. Evaluation goes from left to right and stops as soon as an unset variable is encountered.

What does that mean? Bascially, if the users clicks a button, you want to see if they did it.

$info = ""';

if (isset($info)) {
    echo " Info is blank";

The above script will validate if info is set or not.


Category: PHP Script | Comments Off on About Isset()

CakePHP- First Impression

Recently I got an introduction to frameworks.  Although there a several hundred different types each offering a different set of features and abilities I focused on one the more popular PHP Frameworks.

Here is a list of PHP Frameworks.  The list is astonishing.  The most popular frameworks are CakePHP, Zend, and Code Igniter.

The people developing CakePHP have created a very through framework that allows easy database access.  CakePHP is uses a Ruby on Rails convention, of several folders that break apart the code for pages.  This can be extremely confusing for the beginner.  After working with the system you quickly understand the purpose.

In future posts I will explain CakePHP development further. CakePHP has a well developed base of people to help program with the framework.

Have I missed your favorite framework?

Category: PHP Script | 2 Comments »

Why use an array?

Recently, I asked myself the same question.  You might be wondering, what is an array.  According to Wiki:

In computer science an array [1] is a data structure consisting of a group of elements that are accessed by indexing.

What does that  really mean?  Well, I’ll explain by using an example I got off one of the programming forums I frequent, I will actually quote some of Johnathan Sampson’s message because it captures the idea.  In his example, if you were creating a an image uploader, and you did not want to allow executable files, you would do something like this:

$fileTypes = array("jpeg","gif","jpg","bmp");

Without the use of an array, it would turn into this:

if ($fileExtension == “jpeg”) {
# Approved
} else
if (
$fileExtension == “gif”) {
# Approved
} else
if (
fileExtension == “jpg”) {
# Approved

Or this:

if ($fileExtension == “jpeg” || $fileExtension == “gif” || $fileExtension == “jpg”) {
# Approved

The array makes the code, much easier to handle, and looks cleaner.  Have you used arrays in your projects?

Category: PHP Script | Comments Off on Why use an array?

Easy Site-Wide Link Updating

As I have created more websites, I have come to love includes.  They are useful when you need to use one file repeatadly.  For instance, you may want the same navigation scheme across a site.  It would be troublesome, or bothersome to insert you navigation code on each page.

What happens when you add or subtract a page? You would have to change every single page.  9 times out of 10, you always miss at least one page.  There are other situations where using an include would come in handy, but those are more programming oriented.

You will need:

  1. PHP (in this case), or ASP based server
  2. Main Page
  3. Navigation Page

This code requires the use of PHP, on the main page you need  to write, and so this page must end in .php, for example, index.php.  The ending php tells your server it needs to do more work with that page before displaying it.

Whenever you are using a PHP tag, you must enclose it in

<?php **Place Code Here** ?>

On the every page you want this content to appear insert the code:

<?php include(“file directory here/link.html”);  ?>

This tells the server to include “file.html” in that place on the page. Now, you create “link.html”.

<li><a href=”index.php” title=”Home”>Home</a></li>
<li><a href=”contact.php” title=”Contact Us”>Contact Us</a></li>
<li><a href=”location.php” title=”Location”>Location</a></li>

Now upload these pages to your webserver and only update “link.html” as needed.

Category: PHP Script | Comments Off on Easy Site-Wide Link Updating

Automatic Copyright Updating

Many people who design websites put copyright dates on every page of their website.  By inserting this snippet of code your site will bringing in the new year with an up to date copyright date.

Today this snippet will output Copyright 2008 Resnodesigns and next year, it will greet the New Year with Copyright 2009 Resnodesigns.

Copyright <? echo date("Y"); ?> Resnodesigns
Category: PHP Script | Comments Off on Automatic Copyright Updating