PHP Sessions: Part 1

It’s time to learn about sessions in PHP.

Here is some basic code to start a session, and display the resulting $_SESSION superglobal:

<?php

session_start();

echo '<pre>';
var_dump($_SESSION);
echo '</pre>';

The resulting output:

array(0) {
}

To prove that it’s working, simply comment out the session_start() call:

<?php

//session_start();

echo '<pre>';
var_dump($_SESSION);
echo '</pre>';

Which results in:

NULL

So now I know how to turn sessions on. Next, I need to understand a little more about how sessions work.

The complexity of programming

In my last blog post, I built a basic “Hello World” app using the Slim Framework.

Today, I decided to take a look at the tutorial provided by Luka Peharda on Code Forest called Creating simple tasks app with Backbone.js and Slim micro framework.

It’s a good tutorial, although in my opinion, the author assumes that the reader has more knowledge than they actually might. I found phrases like “Project entity routes are analog to this so we’ll skip it.” quite frustrating. I don’t even know that means. I have no idea what he skipped.

Then there is this: “I won’t go through what Backbone is and why and where you should use it. If you are reading this article then you already know this stuff.” Wrong. Until I started this tutorial, I had never even heard of Backbone.js. As I write this, I still don’t really know what it is yet.

Now I need to say that I appreciate the tutorial, and I am by no means complaining. The fact that I don’t know some of the things referred to in this tutorial just means I have a lot more learning to do.

What I wanted to do here is list the dependancies which were generated as a result of reading this tutorial. It seems that in order to fully understand this tutorial, I’m going to need to learn:

Slim (what I originally set out to learn)

NotORM (Never heard of it before)

Backbone.js (Never heard of this either)

Underscore.js (Apparently Backbone.js depends upon this!)

That’s a lot to grasp! But, no one ever said that programming was easy. (Well, I’m sure it’s been said, but you know what I mean!)

So I’m going to start at the bottom of that stack, and try to grasp each concept. Hopefully when I get back to the top, and continue the tutorial, it’ll all make good sense, and I’ll have a few more tools in my belt.

Thanks again to Luka and Code Forest for providing the tutorial. I appreciate you stretching my knowledge!