A little confuzzled ;> Just some clarification if possible

Hello, I’m currently learning html > css > php and mysql > javascript/jquery/mootools specifically in that order.

I think I have sufficient knowledge in html and css to move onto php. Which
is why I bought roughly 10 different php books, and signed myself up to lynda.com to watch their video series (essential training).

This means I’ve learn’t the following (roughly, though the light-bulb moment still hasn’t happened yet):

Using PHP and HTML interchangeably
Using phpinfo(), and understanding all the parameters displayed
The famous Hello World!
Adding Comments i.e // /* */ hash key doesn’t work on my keyboard :smiley:
Variables
Variable variables
Strings
Arrays
Multi-dimensional Arrays
Functions
Validations
Error Checking
Loops

And all that good stuff…

So far this has been learnt from online tutorials, going through roughly now 7 chapters of the book “Friends of ED, PHP Solutions - Dynamic Web Design Made Easy” and first few chapters of the lynda.com video series (just so you can get an idea of what I should know)

I’ve only been at this 4-5 days so it has been a lot to digest, but I found looking at code that I didn’t understand, reading it all, going back to earlier chapters to brush up on certain things gave me clearer understanding and then the “Aha!” moment.

The problem is, I think I would progress much better knowing the answer to my specific question (and I think I may know it, but I need it explained). But the way I’m going to ask it isn’t going to be short or simple at all, if anyone is willing to then answer a dummies question, I’d be forever indebted to you. I’m learning PHP first as a hobby, and a new found love for programming (scripting?), second to be able to develop solutions that I’m continuously tired of employing others to do, or buying products to achieve it, and then my most distant objective is to freelance (why not put your eventual knowledge to good use right?).

Right, first to get the skeletal part of the question out of the way:

I keep thinking that a site with PHP scripts need to all interact with each other in some way, thus meaning you have to specifically know in what order they go, for example:

Let’s say a user first has to log-in (for our sake, let’s say it is an E-commerce website), on login they get their details displayed somewhere on the page they are currently on (usually on the far top right in the header), and then they can also go to an accounts page to change info. Then the site has a script for validating user registration, logins and also sessions timers (don’t know what to call it) so that users are logged out if left inactive for a while (no risk of others using their account). A shopping cart also exists and a few other features like a cms and so forth…

Would all these things have to go in a specific order, and do they have to somehow connect as one block of code, or can they go anywhere in the page (assuming order from top to bottom, if infact it does need ordering)?

Now, let’s use a real world example so you understand my question in more depth. The site I’m going to use is specifically what I’m going to set myself as my first (and long-term project), mostly because it requires features that you can create independently and test them before adding them to a website (logging etc):

The websites are as following:

Games at King.com - Play Free Games
Play Games Online For Cash - Solitaire, Bejeweled 2 and More Online Games - WorldWinner Cash Competitions on GSN
Play and Win Cash Games - Skill Addiction
Online Games and Free Online Games - GameDuell

but I’m only going to use one of them as an example, though they are pretty much in some way or another have the same features.

Questions will be dotted around this explanation just so you know. If I specifically would like an answer to something but it doesn’t seem clear that I would like one, I will bold.

Starting with the website king.com,

the front page displays different things depending on whether a user is logged in. I suppose this is done with PHP? and if not that atleast asp or jsp or something?

For our sake, let’s just say that it’s done with php. Would this mean that you’d simply need an if statement to see whether a user is logged in or not, and if it results in false, the things that load are different to those if you were logged in.

For example, the right sidebar under the search bar displays as an advertisement if you are logged out, but if you are logged in it shows a user menu.

Under that if you are logged out it only shows you the games available under categories, and the jackpot for the top game in a category. If you are logged in, you instead get a whole host of other sidebars located to the right, with all games listed under each category showing the jackpot available for that game. Would these all have to go through the if statement individually or could they in some way be done in one go all together?

I think with that example in mind, you should get the type of question I’m trying to ask, which means looking at the different functions of a webpage top to bottom and asking whether they actually have to be performed in a specific order, do they have to be scripted individually, and does the block of code have to in some way connect with each other.

Aside from that question, I have one, maybe two more questions if you don’t mind. The first I think has to do with both php and databases.

When a user logs in, on the top right they have a box showing amount of jewels, account balance, and a set of icons that label the following:

“My account page”, a page different to the home page, sign-up and see what I mean.

“My Friends”

“My messages”

“My Games Page”

Let’s consider the account balance and jewels first. This is only a guess, as I haven’t move into the mysql chapters just yet. But is a database made with predefined fields? So under a users name there would be a field with jewels, and everytime a user did something to acquire more jewels, php would simply converse that to the database and update the amount of jewels a user has.

Does PHP simply go to the database, check under a users table, and look at the field jewels to grab the number of jewels that user has to display it on the page that user can see?

Guessing, if this is the case, the same would hold true for the account balance?

And would the same be for any currency, or features such as add friends etc?

Last question (I promise), a lot of wordpress themes only have 1 index.php file, yet they can create a ton of pages that can’t be seen even if you log-in to your own ftp and check the public html folder. Is this because most wordpress themes layout is the same throughout most of its pages and the only thing that needs updating is the content displayed (images, text, links and so forth), and if so does that mean that all it does is communicate with a database to grab the content inserted to display?

Like a site such as Play and Win Cash Games - Skill Addiction, when you click on my community for example, it sends you to [url=http://skilladdiction.com/blog/]Play and Win Skill Gaming - Blog but shows no extension, how is that?

I’ll stop there, as I think I’m pushing it a bit :stuck_out_tongue: I’m finding all this so fascinating yet frustrating because I feel if I knew some of these answers, a lot of the learning would come a lot easier to me.

For those who think, “who the hell is this kid and why is he asking so much as his first post”, I think I, at the very least, owe you some form of background.

I’ve been using computers since I can remember (I’m 22), so definitely 12+ years, even back when we used floppy drives, and used windows prompt as an interface (I think that’s it, I’m not really sure, as I was really young). My dad had a computer with a sports betting software that allowed him to compute several calculations. This was to bet on football teams winning, losing, and drawing in the league. Needless to say, he won quite consistently so the software can’t of been that bad. Back in those days, the whole shadoodle would have been equivalent to a system worth several thousand (I think).

From there I developed a love for playing multiplayer games, and attended my first Local LAN party at the age of 15 (local meaning national really, but because this forum brings people from all walks of life, it can be considered local).

I became ridiculously good at playing games and became what is now called a PRO Gamer, earning money going to different tournaments and winning. I got sponsored by globally recognized brands such as Intel, AMD, EA GAMES, Razer, Puma, Addidas, Alienware (now DELL, so basically sponsored by DELL), and my most recently pleasing sponsor (LG), for sending me this great LG FLATRON W2252TQ, free of charge.

Though my most memorable sponsored product given to me was the XPS Gaming Laptop (I don’t think this laptop needs any introduction ;P), though it had to be returned due to the ending of my contract, and unfortunately, my gaming career. Although I did get to keep a lot of sponsored gear, including my LG monitor which is great.

I made my yearly income doing this, and have till now enjoyed it as both a hobby and work. But I’ve now found another deep enthusiasm towards web development and design, and being the way I am, I become obsessive and spend a ill inducing amount of hours dedicating my time towards it (mostly because I refuse to be “just alright at something”, I have to be the best, damn I’m competitive).

That, in a nutshell, is me.

My name is Jason, and anyone wanting to check out some of my gaming history can check under this username. I look forward to p*ssing incredible amounts of people of with my bombardment of questions, but on a serious note, I hope to both learn and teach eventually :slight_smile:

Thanks, and till next time, or atleast until someone replies :smiley:

I keep thinking that a site with PHP scripts need to all interact with each other in some way, thus meaning you have to specifically know in what order they go, for example:

Let’s say a user first has to log-in (for our sake, let’s say it is an E-commerce website), on login they get their details displayed somewhere on the page they are currently on (usually on the far top right in the header), and then they can also go to an accounts page to change info. Then the site has a script for validating user registration, logins and also sessions timers (don’t know what to call it) so that users are logged out if left inactive for a while (no risk of others using their account). A shopping cart also exists and a few other features like a cms and so forth…

Would all these things have to go in a specific order, and do they have to somehow connect as one block of code, or can they go anywhere in the page (assuming order from top to bottom, if infact it does need ordering)?

Is the first set of questions.

I’m having trouble finding out what you’re asking. Post a new post with ONLY the questions in it.

Sorry if posting directly after is not allowed (mostly due to bumping, but this is to segregate my questions a little)

This is the next block of questions:

Now, let’s use a real world example so you understand my question in more depth. The site I’m going to use is specifically what I’m going to set myself as my first (and long-term project), mostly because it requires features that you can create independently and test them before adding them to a website (logging etc):

The websites are as following:

Games at King.com - Play Free Games
Play Games Online For Cash - Solitaire, Bejeweled 2 and More Online Games - WorldWinner Cash Competitions on GSN
Play and Win Cash Games - Skill Addiction
Online Games and Free Online Games - GameDuell

but I’m only going to use one of them as an example, though they are pretty much in some way or another have the same features.

Questions will be dotted around this explanation just so you know. If I specifically would like an answer to something but it doesn’t seem clear that I would like one, I will bold.

Starting with the website king.com,

the front page displays different things depending on whether a user is logged in. I suppose this is done with PHP? and if not that atleast asp or jsp or something?

For our sake, let’s just say that it’s done with php. Would this mean that you’d simply need an if statement to see whether a user is logged in or not, and if it results in false, the things that load are different to those if you were logged in.

For example, the right sidebar under the search bar displays as an advertisement if you are logged out, but if you are logged in it shows a user menu.

Under that if you are logged out it only shows you the games available under categories, and the jackpot for the top game in a category. If you are logged in, you instead get a whole host of other sidebars located to the right, with all games listed under each category showing the jackpot available for that game. Would these all have to go through the if statement individually or could they in some way be done in one go all together?

I think with that example in mind, you should get the type of question I’m trying to ask, which means looking at the different functions of a webpage top to bottom and asking whether they actually have to be performed in a specific order, do they have to be scripted individually, and does the block of code have to in some way connect with each other.

Aside from that question, I have one, maybe two more questions if you don’t mind. The first I think has to do with both php and databases.

When a user logs in, on the top right they have a box showing amount of jewels, account balance, and a set of icons that label the following:

“My account page”, a page different to the home page, sign-up and see what I mean.

“My Friends”

“My messages”

“My Games Page”

Let’s consider the account balance and jewels first. This is only a guess, as I haven’t move into the mysql chapters just yet. But is a database made with predefined fields? So under a users name there would be a field with jewels, and everytime a user did something to acquire more jewels, php would simply converse that to the database and update the amount of jewels a user has.

Does PHP simply go to the database, check under a users table, and look at the field jewels to grab the number of jewels that user has to display it on the page that user can see?

Guessing, if this is the case, the same would hold true for the account balance?

And would the same be for any currency, or features such as add friends etc?

Last question (I promise), a lot of wordpress themes only have 1 index.php file, yet they can create a ton of pages that can’t be seen even if you log-in to your own ftp and check the public html folder. Is this because most wordpress themes layout is the same throughout most of its pages and the only thing that needs updating is the content displayed (images, text, links and so forth), and if so does that mean that all it does is communicate with a database to grab the content inserted to display?

Like a site such as Play and Win Cash Games - Skill Addiction, when you click on my community for example, it sends you to Play and Win Skill Gaming - Blog but shows no extension, how is that?

Is the 3rd section of my questions. Most of it is the same question, but I repeat it in other forms because I type too much and don’t know when to stop :smiley:

And that’s it, these are the 3 sections in which I ask a few questions, though probably hard to understand what I’m trying to ask because I babble on too much :smiley:

It can be done in any programming language, Python, Php, Ruby, and all other server side languages.

PHP


if ($logged){
 echo "Welcome back.";
} else { 
 echo "Please login.";
}

Ruby


if logged do
    print "Welcome back."
else
    print "Please login."
end

The account balance and jewels is stored in the same database table that stores the user information, the user table. The other tables such as messages and friends have a column called userid.

Many cms scripts use what’s called a front controller which means that EVERY single page goes through index.php. It’s the role of Apache extension mod_rewrite to rewrite the url, to give it a mask. Just like how the Sitepoint forum doesn’t have a real folder called php-34, although on Wordpress you can use 2011/03, in the url, chopping off the post title, and see the archives. The url’s are a trick, internet noobs think the real folder exists but it really doesn’t.

If you cannot ask 3 simple questions without convoluting up a thread, you probrably shouldn’t be learning to code.

When information needs to be passed between web pages you would use a session to keep track.

From your description of what you are trying to do it sounds like you are trying to start with one of the more complex things that you would do with PHP. You should start out with trying to learn the simpler things that work within a single web page and only once you get that all figured out move on to where your scripts start interreacting between pages.

There are two main ways all the components on all the pages you’re looking at are connected. I think once you know that the majority of your questions will answer themselves.

  1. Sessions. Sessions are a way to store information about the people currently using your website. When you visit any of these websites and log in, they start a session for you and write some data into the session to remember that you’re logged in, like so:
session_start();
$_SESSION['logged_in'] = true;
$_SESSION['username'] = "johnny";

When you start a session in PHP, PHP will generate a random unique identifier for that session, and send it to the browser as a cookie called PHPSESSID. At the same time, it creates a file on the server’s hard disk linked to that identifier, and writes any data you save to the session into that file (the fact that the user has logged in, and their username, in the example).

Like all cookies, that cookie will be sent along with every subsequent request to webpages on the same domain until the cookie’s expiration (which for session cookies is set to “this session”, i.e. until the next time the browser window is closed). PHP will see this cookie and when you type session_start() in your code, automatically load the associated session file off the disk and restore all the data you saved about that person into the array $_SESSION for you to use again.

  1. Databases. As you surmise, things like a user’s login details and profile, and how many jewels they’ve earned playing games, are stored in a database. Typically it’s a relational database like SQL Server, MySQL or Postgres. The types of data you’re going to store and the relationships between it are all predefined before you start storing and retrieving anything from the database.

As an example, when a user fills in a login form, your PHP script will take the username and password provided by the form and use them to send a query to a database. You’ll be asking the database if there are any records (rows in a table) with that username and password pair. If it responds that there is such a row, then you can “log in” the user by starting a session and storing the fact that the user is logged in into the session. All other pages of the site can now know the user is logged in, without checking the username and password again, by referring to the data in the session.

In this case the website is written with Java, but it’s the same idea for whatever language is used.

Yep.

session_start();
if (isset($_SESSION['logged_in'])) {
  //do something for logged in user
} else {
  //do something different for not logged in user
}

There are many, many ways to end up with the same output. Exactly how a specific site did it only they know since you can’t look at their source code.

They could have a separate “if” conditional at each point they display something different to logged in users or not. More likely they have a separate template for the whole page for logged in users and guests, and load the whole page appropriate to the current user.

I think you get the idea already, but there are ways to write things so that they have to be in specific order from top to bottom, and there are ways to write things so they are all independent. The way all your pages and all your bits of code within the same page communicate about a user are primarily sessions and databases.

Yes, that’s right. There may or may not be a single field called “jewels”; they could also store how many jewels you earned in each game, and produce that single count on the webpage by adding them all up.

Essentially, yes.

Yes, the PHP code would query the database for the user’s balance.

Yes. That index.php file is called a front controller. The PHP code examines the URL the user typed and uses that to determine what template to use ([url=http://codex.wordpress.org/Template_Hierarchy]WordPress Template Hierarchy) and what data to ask the database for. It provides this data to the template file, which is also PHP code, that specifies where it should go.

There need not be any connection between HTTP request URIs (the part of the URL after the domain) and files on the server’s hard drive. You can create any mapping between the two that you want. You can have requests to /blog execute spaghetti.php and requests to /forum served by steak.php, or send every request to cheese.php and have cheese.php decide what to display for that URL.

Most sites that are serving requests that don’t map 1:1 to filenames use something like mod_rewrite. If you look in the .htaccess file of a WordPress blog installation, you’ll see the “rewrite rules” used to send all requests that aren’t for a static file to WordPress’s index.php file.

Welcome to the SitePoint forums, Jason :slight_smile:

That’s unnecessarily rude and it seems obvious to me, reading Jason’s post, that he is someone who will be excellent at programming.

I’ve been coding in php for years, and I’ve never used mod_rewrite, regex, or a front controller. Fegall is right.

Thank-you, you’ve answered 2 of my questions, though the examples above had nothing to do with what I was asking, and I know how to do them.

It’s not that I can’t condense what I want to say, but rather I don’t stop myself from putting in as much description as possible.

The answer you gave me only validates what I already explained. I just needed clarification to know where I was right or not.

That’s a bit harsh to say I shouldn’t code, especially when I want to do it out of fun, and because I’m enjoying it :slight_smile:

There is of course one example you did not answer, perhaps because my question was so long-winded that you missed it:

but here is a more “condensed version for you” :):

Do scripts have to go in a certain order on a page? i.e

A page that consists of a login form and other features. Do those have to go in a specific order?

Or does that only hold true if it has to happen on page load, or if to use one thing another thing must be declared?

I think I’ve answered my own question in the first post anyway. If I were logged in on king.com, and I clicked to the homepage, the code to figure out what elements of a page and data should be displayed would have to be executed first to figure out whether me being logged in is equal to true or false.

I don’t think I’m not made for programming, or the fact that I like to write a lot means I can’t do it :slight_smile: that’s blasphemy! Though I do welcome your input and help, do you really think I shouldn’t program then? if only because I enjoy it? :smiley:

Thanks!

My apologies, a ton of replies have appeared since my last post. Thank you for your help, and I will now continue to read them :slight_smile:

*EDIT

Thank-you Dan, those are brilliant responses, and easy to understand too! Thank-you for the compliment too :slight_smile:

Do scripts have to go in a certain order on a page?
No. The only thing that should go at the top of a php page is the config.php file which connects to the database, starts the session and stuff; including class files, and then the code for logging in and out, as the setcookie() function requires that no output is echoed before that.

Apart from that, everything below setcookie() and config.php can go into any order.

Thank you.

By the way I use cookies for authentication (logging in) for my scripts. I have no need to use sessions, as using Opera web browser to change a cookie’s value, won’t be enough to hack into another user’s account. The only ever time I’ve ever used sessions, is to for a shopping cart as I had to persistently store the basket data on the computer.

A session is normally just a cookie that stores a code that identifies a user as they move between pages. If someone has cookies disabled then a session passes the info in the addressbar instead.

I’m going through 10 books with practical exercises:

Building your own social network
Building a gallery and manipulating files
Dealing with forms and bringing them to life
File uploads
Managing Files with php
Simple login with multi-page forms
CMS in more detail and creating one
Web based E-mail
Shopping Cart
Web Forums
Weblogs
User Authentication
User Rating system
Trivia Game

And so forth. I don’t know if those would be enough to begin to start having enough knowledge to build your own scripts (ableit simple ones), and then find ways to make them quicker, more secure and run more efficient overall with testing, asking questions and using other tutorials.

Apart from that it teaches date and time, OOP, templating, using Smarty and building PHP libraries and frameworks.

Which all sounds foreign at the moment so it has to be good :smiley:

I just spent about 4 hours going over MYSQL yesterday, so now I’m as far as being able to create a database directly through MYSQL with the application CRUD, and have learnt finally (after being bedazzled for years as to what PHPMYADMIN was) to use the interface, and send, retrieve and modify data in a database.

I would hope after learning some of the above that I’d be somewhat capable (at the very least) of creating small scripts without the help of a tutorial or a ready made script, even if its really simple.

I really like the project I’ve set myself because if you take some of the functions of the website apart, they are based off things you are taught in these tutorials, like a login system, authentication, securing it better, adding more options to user accounts, and so forth.

This way I’d be able to create those things on their own in my own time, and as a final project later on in time, add those together to make the final piece.

Which means I’m learning to use photoshop a little too because I might want to begin to make my websites look a little more pleasing :smiley:

Infact, here’s my first ever attempt at creating something without following a tutorial:

Horrible right? I learnt a few things though that would help me to improve it ten-fold. I just wanted to see if I had it in me to create something simple, yet easy on the eyes and clean :slight_smile:

*EDIT [B]It’ll be interesting when the time comes to learn how to grab scores from flash games, display them according to rank on a page for each player, or store them into a database and retrieve/modify when needed.

That’ll be fun, though I’ve heard this can be done with PHP/MYSQL and a little collaboration with the creator of the flash game.[/B]

That’s good have fun.