PHP Frameworks

framework There are many PHP frameworks out there such as Symfony, Zend, CakePHP, CodeIgniter, and many more. I don’t know that any framework is better in all things than any other framework. I think it’s probably a matter of familiarity and preference. My favorite as of this writing is Symfony. You can read about my experience with Symfony in my other blog.

When I first started using a framework, I was immediately impressed with how much time it cut from my web development. As a free-lance web developer, anything that speeds up my work is automatically a huge plus! My biggest fear with anything that said ‘Rapid Development’ was that it would automatically limit me in what I can and can not do, but I’ve found these MVC (Model – View – Controller) frameworks to be extremely flexible and allow me to do anything I can think of doing. After all, they are built in PHP, so if worse came to worse, I could always change the core code to make it work like I need it to work. Of course, I’ve not had to do this and it’s definitely a good idea not to change any of the core code. Changing the core code will allow updates to wipe out your changes unless you take efforts to keep that from happening. My point is that, as a last resort, I still have that option.

Most websites basically do the same things, so a framework that does all these things for me only makes good sense. There is no sense in reinventing the wheel when it comes to website development. Many websites today are using pretty URL’s which means a routing system is a necessity. Many websites also use some kind of user management and need login, registration, etc. Most websites use forms and need validation. And most websites also need to access a database or files of some sort and can use good data management tools. Frameworks offer these things without having to write the code from scratch. Most of the frameworks handle security, testing, email, and many other features that are common in most websites.

When I use a framework, I only have to worry with my business logic and the design. These make web applications much easier. Much of my code is already written for me as soon as I’ve installed the framework. Development becomes faster, better quality (fewer bugs), and more secure.

Of course, with any good thing, there are also some downsides. One of the biggest for me – and a reason that I built and used my own small framework for a while – is the complexity and constant changes made to the frameworks. I felt that I was constantly having to learn more. I always felt behind in understanding exactly how everything in the framework actually worked. I also felt that I had to constantly be acquiring and reading new documentation which slowed me down.

Recently, I realized that although I spent more time in documentation with someone else’s framework, I spend more time in development with my own framework. So, even with more reading, learning and documentation, I was still developing faster with the open source framework. I’m moving back to Symfony instead of trying to go it alone, even though, I have a pretty darn good little framework of my own.

Regardless of whether you have your own framework like mine, or you are using someone else’s framework, it will save you development time. If you haven’t used one before, you will be surprised at how much work it will do for you!

Did you like this? Share it:
Posted in Intermediate, PHP, Tools | Tagged , , , , | Leave a comment

jQuery fancybox ‘*.support not defined’ or ‘b.support not defined’ Error

Wrong! I was trying to use the jQuery plugin fancybox today. I followed all the instructions but kept getting this error:

*.support not defined

When I used the packed version of fancybox, I got this error:

b.support not defined

After pulling my hair out, searching Google and still not finding any answers, I decided to use a different version of jquery.js. That worked!

Apparently, the version of jquery.js that I was using was an incompatible (maybe old?) version. I finally used the version from here:

http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js

Maybe the next person who makes the same stupid mistake will find the answer much quicker than I did!

Did you like this? Share it:
Posted in Easy, jQuery | Tagged , , | Leave a comment

Building Dynamic Subdomains

Grab Domain I’ve worked on several sites lately where my client wanted each of their website members to have their own subdomain. Typically, when you set up a subdomain it takes up to 72 hours for the DNS to propagate and start working. I’ve been trying to find a way to allow subdomains to start working right away somehow in my code.

Through trial and error I figured it out. If you are using cpanel, you can click on the subdomain icon or link and add a wildcard subdomain. The wildcard is just as asterisk (*). It should look something like this:

wildcard subdomain

The Document Root should be set to wherever you want to handle the incoming request. In this case, I have it set to my public_html folder where I will then dispatch the request to where I want it to go based on the subdomain typed in the address bar.

Now, any subdomain that is typed in the address bar will come to my site unless I have an actual subdomain set up in the DNS – those are handled first by the DNS. For instance, if I don’t have any regular subdomains set up for my website, then with the wildcard sudomain setup regardless of what I type in for the subdomain, they will all be directed to my home page:

cindy.cindycullen.com
whatever.cindycullen.com
info.cindycullen.com

Since I don’t have any of these setup as actual subdomains, the wildcard handles these and sends the request to my home page at cindycullen.com.

If, however, you use one of these:

domains.cindycullen.com
webtips.cindycullen.com
programming.cindycullen.com

they will go to the correct location. The DNS intercepts since I have them set up as true subdomains.

I can find out the subdomain used by the wildcard to reach my script by looking at $_SERVER['HTTP_HOST'] or $_SERVER['SERVER_NAME'] inside my script.

Using the wildcard subdomain keeps me from making my members wait until their subdomain has propagated. I can just handle the dispatching in my code for the domain.

Problem solved.

Did you like this? Share it:
Posted in cpanel, DNS, Intermediate | Tagged , , , , | 2 Comments

Daily Web Tips Not So Daily

You may have noticed that the daily web tips have been missing the last couple of days. This is because I have been at the PayPal 2010 Innovate conference. A pretty good conference, but it kept me busy. I didn’t have the time to devote to the blog that I wanted. And now I am headed back to the Great State of Tennessee. I am exhausted and have decided to put the web tips on hold for a couple of days or so.

Actually, the PayPal conference gave me some pretty good ideas of my own that I want to spend some time fleshing out and working through. Depending on where those ideas lead, I will decide the future of the web tips blog. I hope this hasn’t been too much of an inconvenience.

Did you like this? Share it:
Posted in CSS | Leave a comment

CSS Only Menus

This morning I stumbled upon this set of CSS-Only menus. Since I don’t claim to be a CSS guru, I like to find these kinds of sites. It helps me to learn good CSS coding. Firebug allows me to check out the CSS and change things to see what would happen. I like having CSS only menus since I’m not really good at making buttons with Photoshop.

Did you like this? Share it:
Posted in CSS, Easy | Tagged , , | Leave a comment

CSS Cheat Sheet

I found this cool CSS Cheat sheet today.

Did you like this? Share it:
Posted in CSS, Easy | Tagged , | Leave a comment

The Disappearing Database! ‘MySQL server has gone away’

GoodbyeI have a script that I run every night. This script reads an XML feed which pulls from a MS SQL database and then updates a MySQL database.

The XML feed is rather large and the server where the XML feed comes from is rather slow.

I’m not the only one who thinks so – cURL kept timing out waiting for the XML feed to load. I had to increase the cURL timeout option:

curl_setopt($curl, CURLOPT_TIMEOUT, 120);

I finally got the XML feed to load properly, but then I started getting errors with my MySQL queries:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /mypath/myscript.php on line 30

I looked and looked for the error in my select statement and in my mysql_num_rows function call. These calls had worked just fine in my test code.

The next error gave me more clues:

MySQL server has gone away

After a little research, I found that this error is thrown when your database connection times out. Now, I’ve moved my database connect string below my xml load function. Hopefully, waiting until after the large xml file is loaded will keep my connection from timing out.

Maybe tonight my database won’t disappear again!

Did you like this? Share it:
Posted in Intermediate, MySQL | Tagged , , , | Leave a comment

PHP Data Objects (PDO)

dataPHP Data Objects or PDO is an extension for PHP that gives a consistent interface for accessing databases. Each database will have it’s own driver that must be installed or enabled in your PHP installation. It gives me a data-access abstraction layer which allows me to change the underlying database type without changing my code.

PDO also allows me to access my database in a more object oriented manner which is always a plus.

PDO allows me to use prepared statements which enhances security and performance if used correctly.

Here is a good tutorial for using PHP PDO.

Did you like this? Share it:
Posted in Intermediate, MySQL, PHP | Tagged , , , , , | Leave a comment

jQuery Pop-up – Facebox

My new favorite jQuery pop-up plugin is facebox. It gives a Facebook style pop-up box and it’s REALLY easy to use.

Basically, just include the CSS and JS files in your web page and one or two lines of jQuery code at load, then any anchor tag can create a pop-up box.

The jQuery code:

jQuery(document).ready(function($) {
  $('a[rel*=facebox]').facebox()
})

Then I can use the anchor tag like this:

<a href="#div_id" rel="facebox">click here</a>

It can’t get much easier than that!

You can find out more about the plugin here.

Did you like this? Share it:
Posted in Easy, jQuery | Tagged , , , | Leave a comment

What is an SSL Certificate and Do I Need One?

SecureAn SSL Certificate is a security measure for websites that gather sensitive information from it’s visitors.

SSL stands for Secure Socket Layer.

If you are going to gather sensitive information such as Social Security numbers, credit card information, or any other information that your visitors may deem private and want to keep secure, then you should get an SSL Certificate.

SSL Certificates are digital signatures that basically do two things: 1) – encrypt the information sent between your website and your visitor’s browser and 2) – verifies that your website is, in fact, the website that is getting the information passed from the visitor’s browser.

If you have an SSL Certificate installed on your website then you are allowed to use the HTTPS protocol which is a secure, encrypted protocol that checks to make sure that your website is really the website that the browser thinks it should be contacting. Your website and the visitor’s browser will send extra, secure code back and forth that will give an error if another website tries to intercept the transmission.

When the HTTPS connection is used between your website and the visitor’s browser, the data is encrypted so that it can’t be understood by anyone or anything that is intercepting the transmission.

That is a very basic explanation but should help you understand whether you need an SSL Certificate or not.

If you are sending sensitive information from your browser to someone else’s website, then you should make sure that you are using a secure connection. You should see a lock icon or some other indicator in your browser as well as the https://protocol being used in your browser’s address bar. If not, then don’t send any information that you wouldn’t want public.

Did you like this? Share it:
Posted in Easy | Tagged , , , , | 2 Comments