PHP Category

Process Your PHP Form POSTs Faster.

The Scenario:

You setup a contact form for people to send you email.  When the form is submitted, you want to assign each of the POST, GET or REQUEST values to a variable with the same name as the key. (You could do this for a number of reasons, but that’s a different topic.)

The Problem:

Ugh! Doing this can be really time consuming, especially if you have a really long form.  Presonally, I would just use the array element vs. setting creating a new variable, but if you must, I suggest using a foreach() loop to create the variables for you.

The Solution:

Read the rest or post a comment »

Script.aculo.us and TinyMCE Incompatibility Solution

I found that when I tried to use Script.aculo.us and TinyMCE together, that I lost 1 functionality of one of the two scripts on Firefox. The solution I found was

Read the rest or post a comment »

Working With A PHP Configuration File

TRUE or FALSE: “It’s easier to update one file or 10 files.” This statement is True.

The concept of a configuration file is that it stores data in one location that any other file on the web site can access. The data that is stored in a configuration file can be unlimited, but usually contains data such as by not limited to the following:

  • MySQL Database, Username and Password
  • Document Root Folder
  • To use Cookies or Sessions
  • Set time limit for Sessions
  • Custom variables for web applications
  • and etc.

Read the rest or post a comment »

Use As Many PHP Files As You Need

I’m working with a friend – helping him with some dynamic coding – on a web site. The web site was put together by a different webmaster and it functions. The clients needs have changed over time, and changes are need to the site to comply with a few legal things (it deals with housing.) As I begin looking at the PHP code, I can tell the person who programmed it was very intelligent, but fell prey to some of the things that irritate me, and create problems when trying to update the code as I’m doing now.

First, they didn’t comment any of their PHP code, second they did make use of arrays, but did a poor job of it, and they posted all of the forms back to themselves, which brings me to the point of this post. Use more than one file if you have to, and don’t be afraid to do so. Here’s the problem with posting a form back to itself.

Read the rest or post a comment »

Commenting Your PHP Code

About two years ago I started working for a local web firm. It was small, at that time there we’re only 3 of us, and I was the only PHP developer on staff. We had one client who used our services, combined with another web vendor. Normally we just spit out regular static HTML pages for them, until one day something happened, and we were passed a job that required editing some PHP code from the other vendor.

I honestly don’t remember who the client was, or what the PHP that I was editing was used for, all I remember is that it was the worst code I had ever come into contact with. Nothing made sense, the coding method was random, nothing was optimized, and I wanted to re-write the whole thing and start over. Time did not permit a total re-write, so I was stuck editing the nasty code that was before me. So as I made my edits, I started commenting the code, it went something like this…

Read the rest or post a comment »

Looping Through Arrays

One of my favorite time saving techniques is to loop through an array whether it’s an indexed or an associative array, I’ve saved more time on projects by looping through arrays vs. writing code to handle each value of the array. I bring this up because I’ve had to update too many PHP scripts written by other developers where they handle each and every value of the $_POST or $_GET arrays as individual values to be parsed.

Here’s a practical example.

Read the rest or post a comment »

There’s Always A Better Way

I’m a firm believer in the statement, “There’s always a better way.” When I started learning PHP, I assumed that what I was reading was hardcore `gospel` truth. What I realized later as I was trying to maintain my code was, there is a better way to do this. I was really irritated when my epiphany hit me. Irritated that I didn’t think of it sooner, but I was the novice and I chalked it up to learning, then I got really irritated at the authors of the PHP information I was reading because they never provided a clue, “there’s an easier way to do this…”

Read the rest or post a comment »

For PHP Beginners

When I was first learning how to use PHP, I was looking for all the knowledge I could get. I bought book, read tutorials online, what ever I could find, people to talk to. I quickly realized that no two people had the same approach to teaching beginners and, they often made reference to not providing information that they thought to be useful but possibly confusing.

WHAT! Are you kidding me? So while the author spouts off about how this function operates just like it’s C counter part (which I know nothing about), they won’t provide me with knowledge that may be useful to the language I’m actually learning?

So if you’re just starting to learning PHP keep these helpful tips in mind.

Read the rest or post a comment »

A Different Approach to Parsing HTML as PHP

On occasion it’s necessary for me to process HTML files as PHP. Reasons vary, but usually it’s because the clients web site was originally set up as static HTML and we need to process dynamic content, but due to SEO reasons, we can’t change the file extensions.

Generally a simple .htaccess file can handle this process for you and make simple work of the informing the server to parse HTML as PHP. Some people complain of the load that this can put on the server, but I think this argument is unfounded.

What should be a simple solution, can often turn into an enormous problem. Things being what they are, we ran into a server where our simple two line .htaccess file failed to do the job. All manner of adjustments made between the .htaccess file, changes made by our server admin to the Apache httpd.conf file, all failed.

So in the event that these lines don’t work (while all of the Google results say that they do…)

Read the rest or post a comment »