Archive for the ‘Beginners PHP Articles’ Category

PHP Sessions Video Tutorials – Part 3

Sunday, February 17th, 2008

This is part 3 (of 3) of my video tutorials that introduces PHP sessions to beginners.

php sessions video tutorial

The video:

PHP session video tutorial – part 3

Notes from the videos:

Session ID:

PHP sessions create a unique id that is passed on to the user by either a cookie or in the URL string. To be clear, the actual information tracked about the user is stored on the server, the cookie or URL string only contains the unique id that is automatically generated by the PHP session object.


How long do sessions last?

By default, sessions are set to last 24 minutes – although your hosting company could set this to any length of time they want. Once a session expires, the server deletes all information associated with that session. Sessions are kept active by the user hitting pages that have session enabled.

Remember that sessions are not meant as a long term storage solution, that is what databases are for.


Sessions are arrays:

Sessions are auto global associative arrays (on steroids) that can be accessed on any session enabled page. This is yet another example of why knowing arrays is so important in PHP … and in programming in general.

Sessions have to be declared at the very top of the PHP page!

To use session in a PHP page, it needs to be declared at the very top of the page, before anything else, otherwise you will get an error.

-

If any of the above points confuse you, all you need to do is watch the videos and it will all magically become clear.

:)

The video:

PHP session video tutorial – part 3

Thanks,

Stefan Mischook

www.killerphp.com

PHP Sessions Video Tutorials – Part 2

Friday, February 15th, 2008

This is the part 2 of 3 of my videos that introduces the beginner to PHP sessions.

php sessions video tutorial

In this video, I get into practical examples where we see basic PHP sessions in action.

PHP session video tutorial – part 2

Thanks,

Stefan Mischook

www.killerphp.com

PHP Sessions Video Tutorials – Part 1

Wednesday, February 13th, 2008

Hi,

I’ve just released a new beginners video tutorial that introduces people to PHP sessions:


PHP Sessions Video Tutorial

PHP sessions are one of the most important mechanisms in PHP because they solve a fundamental issue in web application development: keeping state on a user.

php sessions video tutorial

If what I just says confuses you, no worries, it’s explained in the video.

This is video 1 of 3 on sessions.

Thanks,

Stefan Mischook

www.killerphp.com

What Makes a PHP Web Application?

Wednesday, November 7th, 2007

Once and a while a get an email question put to me that I think many others are probably wondering about the same thing.

I got this email from Jordan:

Hi Stefan,

I am very interested in learning how to program, specifically with php. I went through all you videos which are excellent!

My main question is, after watching your videos and reading some tutorials I now understand the concepts such as variables, arrays,if statements etc., but have still have no idea how to put these together to create a web application.

I know exactly what I want the site to do but just have no idea where to begin. Where do I begin, is there something I can purchase that will guide me?

The simple answer to this is to just start writing code. Understanding PHP theoretically, is only the beginning of actually truly knowing it. Once you sit down and start writing code, things will seem to magically clear up as you go along.

(more…)

Video Tutorial: PHP conditionals

Monday, September 24th, 2007

PHP Video Tutorial

The following video teaches the basics of conditional statements in PHP; specifically the ‘if’ statement.

PHP conditionals video tutorial

Again, this video is for beginners to PHP and programming in general.

Note to uber-nerds:

If anyone complains to me that this video is to simple, I might hit you with a theoretical article on how aspects (as in aspect oriented programming) can be used to injects meta-data into your objects, without polluting the model.

:)

… Good old Java.

Stefan

Cannot load mysql extension error – Video Tutorial How To

Saturday, September 15th, 2007

I recently ran into the following error when trying to launch PhpMyAdmin from the WAMP icon tray menu:

phpMyAdmin – Error
Cannot load mysql extension. Please check your PHP configuration.

What does this mean?

In a nutshell, PHP cannot find the library (mysql.dll – on Windows) it needs to connect to MySQL.

How can you fix this?

  1. Use phpInfo() to find out what php.ini file PHP is using. It’s near the top.
  2. Go into your php.ini and enable the extension that loads the mysql.dll library.
  3. Set your Windows ‘Path’ to point to the directory where the mysql.dll is sitting.
  4. Restart Windows.

The solution (and more details) can be found in this video:

Tip: Try the full-screen mode for the video .. it’s pretty nice.

I hope you find this useful.

Thanks,

Stefan Mischook (All around nerd.)

www.killerphp.com

Installing PHP and MySQL on the Mac with MAMP

Friday, September 14th, 2007

In my beginners php videos, I recommended XAMPP as the way to easily install Apache, PHP, MySQL on a MAC.

Well, I just discovered something called MAMP at:

http://www.mamp.info/en/index.php

This nifty little application allows you to (really easily) install Apache, PHP and MySQL. You are provided with a standard DMG file that you simply drag to your applications folder.

MAMP has a pro ($) and a standard version … all programmers need (to do their development on their local machines,) is the free standard version.

Once installed you can start MAMP up (and thus Apache, MYSQL) as you would any other program … and this is what you get:

Mamp Control Panel

As you can see, you can start and stop the servers and tweak the MAMP settings (example: where Apache looks for web pages … the Apache document root etc).

The MAMP ‘Start Page’:

Like XAMPP, MAMP comes with it’s own ‘Start Page’ where you can access:

  • MySQL password information.
  • phpMyAdmin
  • SQLightManager

The Screenshot:

Mamp Start Page

Dashboard Widget!

But what’s even more cool, is that MAMP comes with a Dashboard widget:

Mamp Dashboard widget

Conclusion:

I am currently using MAMP to do some test on a PHP based CMS (Drupal) and MAMP allowed me to set up my Mac in about 5 minutes … maybe 4.

Stefan Mischook

www.killerphp.com

Why learn OOP in PHP – another take.

Friday, September 7th, 2007

php logo

Why learn OOP in PHP – another take.

For people new to OOP and are comfortable with ‘classic’ procedural php, you may be wondering why should you even bother to learn object oriented concepts … why go through the trouble?

The PHP world:

PHP is moving in an OOP direction. For example, many important PHP extensions like PEAR and Smarty are OO based. So, to really understand and use these frameworks properly, you need to understand object oriented PHP.

The functional/practical advantages:

For smaller projects, using object oriented PHP may be overkill. That said, object oriented PHP really begins to shine as the project becomes more complex, and when you have more than one person doing the programming.

For example:

If you find that you have say 10-20 or more functions and you find that some of the functions are doing similar things … it is time to consider packaging things up into objects and using OOP.

OOP and your career as a programmer:

OOP is the modern way of software development and all the major languages (Java, PERL, PHP, C#, Ruby) use this method of programming. As a software developer/programmer, it only makes sense (in terms of career,) to keep your skills up-to-date.

Besides making you a more valuable PHP coder, understanding OOP in PHP will give you knowledge (OOP knowledge,) that you will be able to take with you into other languages.

… When you learn OOP in PHP, you’ll learn object oriented programming for any OO based language.

You will find with time that creating OOP based PHP projects, will just make your life as a programmer much easier. As an added bonus, soon you will develop your own collection of reusable objects, which you will be able to leverage in other projects.

Finally, You will also find that OOP based PHP is much easier to maintain and update.

OOP Challenges:

OO PHP does present some challenges when you first start out because you’ll need to learn to think about your PHP projects in a different way: you will need to conceptualise the project in terms of objects.

More details …

One common way of starting an object-oriented project is to start by drawing up simple diagrams of your objects. As you begin to work with object diagrams, you will find that they help make developing OOP based PHP projects much easier.

Here are a few tips about drawing object-diagrams:

· Use a paper and pencil
· Draw boxes to represent each object
· In those boxes, list your methods and your properties
· Use arrows and lines between boxes to denote relationships (parent – child) between objects.

So if you have been sitting on the fence waiting to jump into OO PHP, now is as good time as any to get started.

Stefan Mischook

www.killerphp.com
www.killersites.com

Object Oriented PHP Tutorial Updated – Steps 18 – 22

Thursday, September 6th, 2007

php logo

Hi,

I’ve update my beginners tutorial on object oriented PHP adding steps 18-22.

Again, this is a code intensive article where I expect you to follow along with your PHP editors.

PS: if you happen across any errors/typos, please let me know.

More to come.

Thanks,

Stefan Mischook

www.killerphp.com

Turning on display_errors in WAMP – Video Tutorial

Thursday, August 30th, 2007

PHP Video Tutorial

Hi,

Within a WAMP installation, I ran into a little issue today when trying to change php.ini’s ‘display_errors’ property.

By default WAMP installs with ‘display_errors’ to ‘Off’:

display_errors = Off

… This is a pain-in-the-ass setting when trying to write new PHP code because errors don’t get displayed in the browser window; you have to go to the log file.

So like any good nerd, I popped open php.ini and made the change:

display_errors = On

Problem is that it didn’t work. I soon discovered that WAMP was using ANOTHER php.ini file on my machine!

Solution:

Run phpinfo() and look for the property: ‘Loaded Configuration File’

This will tell you what php.ini WAMP is using.

-

I created a video (with more details on WAMP and php.ini) for those who like to watch.

Thanks,

Stefan Mischook

www.killerphp.com

Object Oriented PHP Tutorial Released

Wednesday, August 22nd, 2007

php logo

Hi,

I’ve just released a written tutorial on object oriented PHP, that targets people totally new to OO PHP.

Beginners Object Oriented PHP

Based on an article I wrote for a web design magazine; the tutorial is presented as a series of simple steps where I walk the reader through the process of building objects while at the same time, exposing them to basic object oriented concepts.

The first 11 steps (of 23) are up now.

-

This tutorial is actually the outline to a set of videos I will be producing in the near future … Just as soon as I am finished with my dental work.

… It hurts I tells you!

Thanks for reading,

Stefan Mischook

www.killersites.com
www.killerphp.com

Classes and Objects in PHP

Wednesday, August 1st, 2007

php logo

Hi,

I’ve written up a short (2 pages,) document that goes over some of the very basics of object oriented programming - it should take you all of 5 minutes to read.

I wrote this as the preamble to my next video on object oriented PHP where we will actually create living breathing PHP objects.

Here’s a small snippet from the PDF:

How objects are created:

Step 1:

You create a class that ‘describes’ an object. Much in the same way a blueprint ‘describes’ a building. Instead of room dimensions etc … PHP classes / blueprints details a bunch of things about an object:

a. Variables it contains.
b. Functions it contains – yep, classes typically have functions in them.

Objects are much more powerful and complex when compared to functions. As such, there are many other special things that can be found in classes, which are unique to classes. Again, more on that later.

Step 2:

Once you’ve defined your class, you are ready to tell the PHP engine to actually create a class from your blueprint. There are special commands (PHP code,) that tell the PHP engine to create an object from the ‘blueprint’ you described/outlined in a class.

Step 3:

When the PHP script is run (with the code that instructs PHP to create an object … based on the class,) PHP actually creates a living, breathing object based on your class.

What I mean by ‘creates a living, breathing object, is to mean that the object is actually created in (server) memory.

Thanks for reading and watching.

Stefan Mischook

www.killerphp.com
www.killersites.com

Database driven websites article: updated and now in PDF format.

Wednesday, April 18th, 2007

A while back I wrote an article for beginners on database driven websites:

‘Database driven websites: what are they and how are they built?’

The article explains the basic concepts behind dynamic websites, with the idea of making learning PHP that much easier. If you’re new to the game (of PHP,) I would strongly suggest that you read this article.

-

In this updated version (available on PDF,) I’ve included a few new diagrams.

Download the PDF: database driven websites

Thanks,

Stefan Mischook

Why are PHP books and videos hard for people?

Monday, April 16th, 2007

I’ve read 20+ books on PHP and have watched many videos. One thing that I found consistent about all of them was how they were not ‘friendly’ to non-nerd types.

Why?

Probably because (most of the time,) only hardcore code-monkeys seem to be writing these books. That means either one of two things:

  1. They forget WHAT made it hard to learn to program.
  2. They never had trouble (in the first place) because they were … well, hardcore code-monkeys!

Fortunately for you, I was not born a hardcore code-monkey (I was hardcore in other areas …) and I still remember those tricky concepts that frustrated me.

With that in mind, I designed the videos to make learning PHP dead simple. In fact (from what I hear,) my PHP videos make learning PHP easier than any other source out there!

Yes, this is a bold statement, but the emails and conversations (from people all around the world) tell a story.

… I used to read and then delete the many comments and emails I would get. But a marketing buddy of mine slapped me off side the head, and reminded me that I should be posting these.

Check out some of the comments below.

Thanks,

Stefan Mischook

Killerphp News

Friday, February 23rd, 2007

Hi,

It has been a while since my last post, my apologies.

But there has been a good reason for this and this reason will be revealed soon.

Sorry I can’t give more information, but I have to keep this under wraps until we go public.

Thanks,

Stefan

OOP in PHP: New PHP article to appear in Web Designer Magazine November’s Issue

Tuesday, November 7th, 2006

I have a new article appearing in issue 125 of Web Designer Magazine – the November issue.

Article title:

Learn Object Oriented Programming (OOP) in PHP

Object Oriented Programming in PHP

Sample from the article:

With the release of php5, php programmers finally had the power to code with the ‘big boys’. Like Java and C#, php finally has a complete OOP infrastructure.

In this tutorial, you will be guided (step-by-step) through the process of building and working with objects using php’s built-in OOP capabilities.

At the same time you will learn:

  • The difference between building a php application the old fashioned (procedural) way, versus the OOP way.
  • What the basic OOP principles are, and how to use them in PHP.
  • When you would want to use OOP in your PHP scripts.

People run into confusion when programming because of some lack of understanding of the basics. With this in mind, we are going to slowly go over key OOP principles while creating our own PHP objects. With this knowledge, you will be able to explore OOP further.

For this tutorial, you should understand a few PHP basics: functions, variables, conditionals and loops.

The article is broken down into 23 digestible steps with plenty of screen shots – makes it really easy to take in the information.

By the end of the article you will have your hands dirty with OOP PHP code … there is not better way to learn programming than to write code!

… I plan (at some point in the near future,) to put out a video tutorial to complement this article.

Thanks,

Stefan Mischook

Killer Ajax FAQ

Sunday, October 1st, 2006

I’ve just posted a quick intro FAQ to AJAX at killersites.com and I thought that some PHP’ers might find it useful as well.

Stefan Mischook

So what is this Ajax thing I keep hearing about?

Ajax is actually an acronym which stands for Asynchronous Javascript and Xml. The term Ajax is used to indicate the main technologies used to build Ajax-enabled web sites. From a user’s point of view an Ajax user interface looks and feels less like a web page and more like an actual application.

The most obvious feature of this is usually that a user can do things that cause what they see in their web browser to change, without the whole page having to be reloaded (for example add an item to a shopping cart).

.. read the whole AJAX FAQ.

What are database driven websites – podcast.

Saturday, August 26th, 2006

A quick podcast where I explain the basics behind what database driven websites are.

This podcast targets total beginners.

Database Driven Websites Explained.

3 Categories of Programming Languages

Monday, August 7th, 2006

From Killersites.com blog:

Recently a more practical way of classifying languages has come to my attention – classifying languages by problem-domain or in other words, context.

* System Languages
* Architectural Languages
* Application Languages

I like this list, because it really conveys a sense of practical use for a language. I’ve hammered out the details below

Read the rest here:

3 Categories of Programming Languages

Will Ruby kill PHP?

Monday, August 7th, 2006

With the recent rise in popularity of the Ruby programming language (largely driven by the excellent but not perfect web framework called Rails), I’ve noticed a little fear in the air … fear on the part of some people in the PHP community.

Will Ruby kill PHP?

The short answer is: no.

MY REASONING

Though Ruby and PHP are both scripting languages that make developing web applications much easier than it is, say in the Java world, they are very different beasts … each appeals to a different audience.

RUBY IS ELEGENT BUT COMPLEX

Before I go on, I want to point out that Ruby is a great language and I think it makes perfect sense for PHP developers to learn a little Ruby: it is always a good idea to learn other languages because it will make you a better programmer.

That said, I believe Ruby will not appeal to, or fill the need of most PHP’ers – Ruby can be a little too abstract.

JAVA NERDS LOVE RUBY

Ruby is attracting many from the Java world because it expresses very advanced concepts in a simple syntax – contrast this to Java’s (often times) kludgy and verbose representation.

Ruby appeals to the Java crowd because Java people have been trained to think in terms of large scale enterprise applications – regardless of the size of the project.

… These ‘abstractions’ (generally speaking) lend themselves well to larger projects.

WHY PHP WORKS

PHP is often criticized because it has both a procedural and an object oriented way of doing things. Some people think that this divergence (within the language), takes away from it … I think this is part of its strength!

Objected oriented constructs are great for creating cleaner designs that are easier to maintain and promote the possibility of code reusability. Code reuseability is an often touted advantage of OOP, but from what I’ve seen in the Java world, it is not achieved so often.

With OOP, there is a cost of added complexity and overhead – you simply have to write more code to do things when you do it via OOP.

PHP PROVES THAT NON OO LANGUAGES STILL HAVE THEIR PLACE

I would suggest that the vast majority of PHP work is found in simple projects:

  • Email from a web page.
  • Process a simple form and save to a database.
  • Create a simple store with 10 items.

My point is, that for many PHP projects, OOP may be a little overkill.

WHY RUBY WILL NOT KILL PHP

In Ruby everything is an object (even numbers!) and the core language has very sophisticated constructs that need to be understood to use Ruby effectively – Ruby strength is also its’ weakness.

… I don’t see the majority of PHP users wanting to jump that deep into the world of programmatic abstraction – for most, there is simply no point.

Stefan Mischook

Top of page  go to top of page