Today, when we say Social Networking Site the first thing that comes to mind is Facebook and if you get asked to name some other social networking media, if you are my age you would probably say MySpace and Hi5. But Social Networking media has been around for more than that!
Shifting I had started using the Internet when I was about 12 to 13 years old and at that time I remember having mIRC, where you could have your own channel and you and your group of friends could log in and chat, share photos, plan to meet up and do the same basic stuff we do today on Facebook. Sure you didn't have profiles, albums, likes, etc... but you get the picture! Then all of a sudden it seemed to have died down and all of my friends were moving on to MSN messenger, but why?
You could do the same things in mIRC, we chatted, exchanged photos and stuff and what not but in my opinion, MSN messenger added privacy! You received requests from other users to chat with you for the first time, whereas in mIRC you could log into a channel and there would be loads of people you didn't know. I remember the first thing we used to say to a person on mIRC was 'ASL?' which translated into AgeSexLocation? With MSN messenger you could know who that person was as everyone had a Profile and this was the golden ticket which made everyone shift. Now you could have albums with pictures of you and your friends, and other people who were on your Friends list could leave comments on them.
This is the reason why there is always something new, if its not MySpace, it's Hi5, but why? Why does the crowd occasionally shift? It all boils down to who has the most competitive edge. Some new guy will eventually turn up with a new feature which no one else has thought of yet and steels the spotlight.
Why has Facebook grown so much If you stop for a while and look at what Facebook is doing, you'll notice that its constantly introducing innovative ideas. First it had the 'Like' button, mutual friends and the photo tag, then it incorporated the instant messaging service within the site its self, video chat, groups, fan pages, maps which record all the locations you were at, multi-player games which display scoreboards made out of your friends and most lately the Timeline profile which illustrates your activity across the years. This constant introduction of new features helped keep Facebook at the top for so long now, but don't think for a moment that its guaranteed to stay there forever. Every beginning has its end and within a few years time we would laugh and ask ourselves why Facebook?
The Dark Side Unfortunately, social networking has its drawbacks, the first which come to mind are; Addiction and Stalking.
Addiction Its true that social networking makes us feel more connected to our friends and family, but is it worth spending 6.7 billion hours on social networking sites? That's the amount of hours spent on October 2011 alone.
Stalking According to an article issued on April 2011 by The Guardian cyber-stalking is now more common than physical harassment and that almost 40% of the victims are males.
Conclusion I just want to conclude with this interesting infographic which illustrates the growth of social networking and how it is effecting our productivity.
Representing the Internet as a cloud in networking diagrams has been done for years now, but lately the term "The Cloud" has become a buzz word.
But what is "The Cloud" exactly? Is it the same thing as the cloud image we are used to making use of in diagrams?
What is it?
Well it got its name thanks to the diagram yes, but its not exactly the same thing. "The Cloud" actually refers to any computer processing or storage provided over the Internet.
A good example of cloud computing is Google Drive (previously known as Google Docs) where you can store your data in "the cloud" (actually you would be storing it in Google's server farm) and work on or create new word, spreadsheet, presentation or form documents online.
Google Drive provides both SaaS (Software as a Service) and Storage Services and meshes them together. With this technology you can easily synchronize multiple computers to the same data.
Advantages
Cloud computing has grown impressively in the last few years and this all boils down to the attractive advantages it provides to its customers, some of which are:
Reduced Costs - Customers don't have to worry about buying and maintaining expensive hardware
Increased Storage - Companies can afford to store more data on the cloud than on their own computers as the service providers will take care of providing enough storage for their clients (this effects the subscription fee, but this would still be more cost effective than buying your own storage devices)
Highly Automated - Applications hosted on the cloud are updated by the service provider (Example: Google Drive never asks you to install the latest update, it's just always up-to-date with the latest version)
Mobility - You can access your data from anywhere you like as long as you have an internet connection.
More efficient use of the IT department - Because the IT guys don't have to worry about keeping the software up-to-date, licensing or maintaining the hardware, they can focus more on innovation and more business required tasks.
Disadvantages
Down Time - If the service provider suffers from down time, so do you and yes even the biggest players in the cloud computing industry occasionally have their bad days:Cloud Computing Service Outages in 2011. Apart from this, cloud computing also depends heavily on your internet connection, therefore if your connection is down you might as well go home.
Security - If you choose a serious service provider, this would probably be more of an advantage that a disadvantage as these companies are guaranteed to have the latest state of the art security software and hardware installed. Software and hardware which you most probably don't afford, if you are a small business and not feasible to maintain. But at the same time there is still that sick feeling that your company's data is out there on the internet and most probably the best hackers are trying to hack into it while you sleep!
Conclusion
To conclude this post, after doing this research on cloud computing, my opinion on the subject is that yes, cloud computing is a good thing and it has its attractive advantages, but don't jump on the wagon just because everybody is doing it. Evaluate the disadvantages, see if you can live with having your data on the internet and then take the responsible decision whether or not shift to cloud computing.
If you remember a while back I had posted on Virtual Learning and had mentioned Second Life as one of the less popular options, well...we gave it another go, as our lecturer was ill and we all attended from our own home.
I'll start off by re-visiting something I had said in my earlier post, where I stated that you only get a chat box for communication. This isn't entirely true as I later discovered you can use audio. But this still didn't improve the experience a whole lot because instead we ended up having the lecturer continuously checking if we could hear him or not. This all boils down to lack of non-verbal communication, because in second life you can't nod your head unintentionally or output a face expression. Without this non-verbal communication it is quite difficult for the person who is talking to determine whether his/her message is going across.
Apart from this, we also met with the same problem we had previously experienced of loosing focus quickly as everyone ended up flying around, attempting to build their own prims (which resulted to a mess of prims all over the place) and basically making a havoc out of the lecture.
Conclusion Sometimes second life is advertised as a great place for education...well it's not! We tried it out and its not effective what so ever, a simple video conversation would be much simpler and would have done a better job as well.
To continue on my list of things to do I decided to create a prim which would give a note card to who ever touches it.
But what is a note card? you might ask...well basically it's a note containing text which is given to an Avatar. This could be given in any way you would like, but the most common is upon touching an object. So basically a note card is a sort of flyer, which normally advertises something.
After carrying out some research on how to do this, I concluded that the following is the most straight forward way.
Creating a Note Card Giver So the first step is to create the actual note card which will be sent. To do this I opened the inventory window from the controls on the left of the screen and went to the "Notecard" folder. Once there I created a new note card and typed in the text I wanted.
The next step was to create an object and for this I decided to create a levitating leather ball (keep in mind that this must attract the attention of the other user, so make yours as interesting as possible).
Once I was satisfied with my prim I went to the "Contents" tab in the Build window and by drag-and-drop, I placed the note card I had previously created under the contents repository of the prim.
Finally I created a new script for this prim and in the "touch_start" state I included the following line of code:
Following the door object I had created in my last post, I felt I had gathered enough experience in using the Second Life Viewer's tools to create another object on my list of thing to do. Therefore I decided to create a bench on which an avatar can sit on.
Building It!
I started out by creating four identical bench feet by first creating one and then held down the shift key and moved the prim to create an exact copy of it. I repeated this process for all fours.
Bench Feet
Then I created the base and back out of two boxes, stretched and flattened them out as required and positioned them appropriately.
Base & Back
Now a wooden bench isn't very comfortable isn't it, so I added some cushions on the back and base of the bench and gave them a red colour just to make it took a bit better.
Cushions
After I was happy with the way it looked I linked all the parts together to make one, but I left the base cushions out as these I want to treat as three separate seating positions, otherwise the bench would be only available for a single person to sit on.
Linked Prim except for base cushions
Scripting It! The final step now is to sit on the object I have create. By default second life offers the functionality to sit on any prim but this might not always have the desired result as the image below clearly shows
Unnatural way of sitting isn't it?
To overcome this I had to create a script in each of the base cushions which determines the exact point where the avatar will sit on the prim and a what rotation.
llSitTarget(<0.4,0.0,-0.60>, <0.0,0.0,180,0.0>;
I must say, at least these things are really easy to script as so many functions already exist in second life that you rarely have to have to create your own.
Hello there and yes unfortunately its about Second Life again but at least today is about the part of second life which interested me, so here goes.
I decided that I wanted to create a door which an avatar could open and close buy touching it, so I set off on building a wall with a door in the middle.
First step to building a door
My next step was to create a hinging point for my door as by default the rotation point of any object is the middle and this is not how a door actually works is it?
Adding the hinging point
Now to join these two objects together in Second Life, you must 'Link' them together by holding down the shift button and selecting the two (or more if you like) objects and finally click Ctrl + L to link them.
It's important to keep in mind that the last object you select will be the root object, therefore I selected the hinging point as the root.
So now I've got a wall with a door in the middle set up with a hinging point, true it's not the nicest looking thing you've ever seen but I decided to leave the looks for the end.
To test if I've done this correctly I first tried changing the rotation of the door via the Building Tools window, by setting a -90 degree value in the 'Z' parameter of the rotation fields and to my surprise...it actually worked!!
No, I'm lying, I had to try it about 5 times until I got it right...which is quite frustrating. But eventually it worked and this is how it looked like:
Manually opened door
But now I wanted to create a script which does this every time a user touches the door, so after doing some research I learnt that you must do this by using the rotation variables of an object.
Every object has 4 rotation values; X, Y, Z and S but to make a door open all I needed to use were the Z and S values.
So I started out by retrieving it's Z and S rotation positions. I did this by writing a script which would get these values and output them on screen every time the object is touched.
The above script is what I'm taking about, it get these values by using the method 'llGetLocalRot()', this method returns an object of type "rotation", which contains all 4 values which I have previously mentioned, then it uses the method 'llSay()' to output the values I require on the screen using channel 0 (zero).
Back to getting those all important rotation values, I close the door once again and touched it to output it's Z and S values like so:
Rotation Variables
I also did this for when the door is opened, so that I know how much I should open it and wrote these values done for now.
Then I re opened the object's script, removed the entry state as I don't need it and left the touch_start state. in here I used an IF statement which would check if the door is closed and open it. If the door is opened instead it closes it by setting the object's rotation variables to the ones I had written down by using the method 'llSetLocalRot()' and passing it the rotation variable which I modify.
Open-Close Door Script
After playing around with some textures this is the final result:
Finished opening & closing door
Conclusion
I must admit I don't quite think the LSL scripting language is one of the best scripts out there but at least with a few lines of code you can visually see things move around or for my last post's case, send an email with by simply using 'llEmail' this fact forces me to admit that I kind of enjoyed doing this today.
In my previous blog I skimmed over what Second Life is, today I am dedicating this post on the subject, what I like and what I don't like about it.
Fist thing that came to mind when I heard about Second Life was...WHY?! What's wrong with my first life? Why would I ever want to take part in a community of a bunch of complete losers and what's with the hole role playing?
Then I learnt that people actually sell land, clothes, accessories and appearances with real money!!! This further pushed me away from Second Life and the people who hang out there.
But I must admit, I already hated Second Life before I had even laid eyes on it and this blinded me from seeing what an accomplishment Second Life really is and that's from a technical point of view only!
I mean the the developers of this thing managed to create a whole virtual world in which subscribers can roam around and build things.
Yes, they enabled any user to build and program things to do anything they very well please and this is probably the only thing I liked about Second Life.
Scripting
So off to the interesting part from now on. To code your own objects you must use the Linden Scripting Language or LSL in short. This scripting language was created specifically for Second Life, it's based on Java and C programming languages and is a server side scripting language.
Now one must keep in mind that LSL is very state and event driven, meaning you do not create objects which have attributes and methods, instead you use states which contain one or more events.
States resemble real life scenarios, as in an engine can be on or off and the same goes for Second Life. By default every object you create has one state and that's "default", but you can create more states and change from one to the other.
Events on the other hand are just like event handlers in other programming languages. These are pre-defined and are triggered by a specific action, such as on touching the particular object, the "touch_start" event is triggered.
But enough about the theory and lets move to my first attempt at building an object and scripting it.
My go at Second Life Scripting
After I spent a few minutes having a go at scripting a twisty box, I managed to make my object send me an email when ever it got touched and this got me excited just like a little boy in a candy shop!
So here's the script I used, nothing fancy and I haven't gotten into using multiple states yet, but it's a start.
default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
}
touch_start(integer total_number)
{
llEmail("grechClifford@gmail.com","Box Object Touched","Object has been touched");
llSay(0, "You Touched ME! - Sent Email to Owner!.");
}
}
As you can see, the "touch_start" event first uses the "llEmail" function which sends me an email telling me that my object has been touched and then uses the "llSay" function to display a message to the user.
As for the result, I immediately receive the email displayed below:
Conclusion So, my final verdict on Second Life...I still hate it as it is still filled with creeps posing as attractive women, but at least there is something which sparks my interest. Although I would also like to say that I am not planning to play this game very often apart for my degree purposes.
In this week's post I'm going to write about Virtual Learning and how we can improve this to make it more realistic and effective, both for learning and for costs.
I shall start off with the advantages of virtual learning. So, the most obvious advantage is location, I am currently enrolled in a Middlesex University Degree, but I attend my lectures in Malta at STC, where I receive my lectures by tutors employed by STC, which have to follow strict rules on what to teach us from module leaders employed by Middlesex University, which are also based abroad.
Now take a moment to think about all this, Middlesex University employs module leaders (which are basically tutors), STC employs other tutors, students pay STC for Middlesex University's course, plus administration charges and tutor wages. Exams are done using a pen and paper, corrected by STC's tutors, shipped to Middlesex University and corrected once again by their moderators. Those moderators have to be based in Middlesex University's campus, thus if they are from a foreign country, they must have left their families behind to work there...see where I'm going?
Virtual learning could simplify this system tremendously by first of all cutting out the middleman, that's STC...sorry I don't mean to put you guys out of business, but in my opinion this is the way forward. Next, students would interact directly with Middlesex University's tutors, while staying in their own country, same goes for the foreign tutors. Middlesex University would also gain from this as it would not have to cater for so many employees in one location, therefore making it possible to operate from a smaller premises.
All of these facts would cut cost tremendously and improve practicality as students and tutors would communicate directly while staying in their native countries...But for this system to be efficient, some things still have to be improved as I will now explain by covering four technologies which will lead to my proposal.
Video Lectures These are nowhere near virtual learning, but its been practised for a number of years now. It consists of a tutor recording a lecture, this recording is either live steamed to students around the world or made available for download to view at a later stage. This alone solves the location problem I mentioned earlier, but it lacks an important attribute...INTERACTION!! Students & tutors cannot interact freely this way, sure some kind of instant messaging system can be used but this is not very convenient as it could be hard to express one's self through writing.
Google Chat To overcome this problem in one of our lectures we tried an experiment in class, in which we used Google Chat to communicate via our devices' web cams and microphones. This enabled each student to see the lecturer and the lecturer could see every student, but this method had a problem as when one of us spoke, his voice was being picked up by more than one microphone, resulting to echoing. True, we were all standing in the same room but even if we were all in separate locations, the sound coming out of out speakers would have had the same effect. Therefore this method was a complete failure without the use of specialised hardware for the job.
Second Life
This is a 3D world where every user has his/her own avatar and can roam around these fictional or quite realistic in some cases, locations. I am planning to dedicate a post for Second Life in the near future, but today I will only mention when we tried to carry out a lecture in it. We all decided to visit Middlesex University's virtual location and meet up in a Greek theatre sort of place, where we all sat down and looked at the lecturer. But for interaction , Second Life offers a chat box and this takes us back to the problem I mentioned with video learning, plus I found the power which second life gives you quite distracting, as in Second Life you can build your own objects and this led to someone building a huge wall which completely blocked off the lecturer from the rest of the class (Although I must admit it was quite funny).
Real Telepresence After doing some research I stumbled upon the following video of a Black Eyed Peas concert where two of the singers where life-size holograms being projected to the audience.
This sparked my interest, as if these guys managed to do this in a concert, there must be a way to use this technology in a classroom setup and after I carried out a bit more research I discovered Real Telepresence.
The DVE immersion room, to be more precise! This makes use of hologram technology to create impressive realistic conference rooms where you can see the other party crystal clear, see every non-verbal communication, make eye contact and hear them as if they were standing in the same room.
My Proposal This got me thinking, what if you could hook up these systems together to allow more than two locations in one large group? Students in multiple countries would go into their local DVE immersion room, (Note to STC: If this idea ever picks up, you can always provide these local DVE immersion rooms) which would have holograms projected on the side as well to show their "immersion room class mates" in order to give them the feel that they entered a large lecture room and the tutor would see all these immersion rooms located in different countries combined as one. The images below illustrate my proposal.
Welcome to the final blog about coursework 2! I have completed all the required coding, so know I am going to post about the last two functions of my game, which are:
Score Keeping
User Notifications
In my 3rd post on this coursework I had shown you the structure of my users table, which consisted of two particular fields; Score and Last_Beat_By. The use of these fields will be explained in this post.
Users table structure
Score Keeping Functionality
So now, to make any game that bit more exiting, it must have some sort of scoring, not only that but scoring is also the unit of measure when users want to compete against each other!
Therefore I was time add this all important scoring functionality to my game and I came up with the following list of things I had to include:
Set up the rules of how points are given or taken
Accumulate on user's latest score
Save the score once the user ends the game
Display a Score Board at the end
Scoring Rules:
I decided to make the user able to increase as well as decrease his/her latest score and to do so I decided on the following way of how this would apply.
Accumulate Latest Score:
For a user to continue improving...or ruining his/her latest score, it had to be queried from the database and stored in memory. This task is handled during user authentication, as when I query for the user's record, I store the user's score in a session variable via PHP, along with other details such as the Last_Beat_By:
function authUser($userID, $password) {
$authUserSQL = "SELECT * FROM users WHERE USER_NAME = '" . $userID . "' AND USER_PASSWORD = '" . $password . "'";
//queries the database for the user record with the received parameters.
$result = execute($authUserSQL);
if (mysql_num_rows($result) > 0) {//record found
$record = mysql_fetch_array($result, MYSQLI_ASSOC);//stores the returned result in an associative array
//stores user's related data in session variables
$_SESSION['userName'] = $record['USER_FULL_NAME'];
$_SESSION['highScore'] = $record['SCORE'];
$_SESSION['lastBeatenBy'] = $record['LAST_BEAT_BY'];
$_SESSION['userID'] = $record['USER_NAME'];
$_SESSION['Authenticated'] = "yes";
return TRUE;
} else {//no record found
return FALSE;
}
}
Score Keeping with JavaScript: After this is done the user gets redirected to the game. To avoid having to retrieve the session variables via JavaScript, I output the session variables to JavaScript variables using PHP as shown below:
var myPaper;//the paper object (image)
var myBin;//the bin object (image)
var binXLocation;
var ammo1XLocation;
Once the paper toss page is sent to the client, the variables which are outputted by PHP will look exactly like all the other variables, therefore keeping in mind that JavaScript is a client side technology, I can reference these variables normally. Back to score keeping, in the above code you can see I am storing the retrieved score in a variable name 'origScore' and then storing this variable in another, named 'newScore'. This is because at the end of the game I want to know what was the user's score at the beginning. I will explain later when I cover the user notifications function.
Now that I have the user's latest score in memory on the client side, all I have to do is increment or decrement this value according to where the paper ball lands, for example:
Saving the latest score: Once the user clicks on the 'End Game' button at the bottom, he/she gets redirected to another page named 'saveGame.php' and the required values are posted to this PHP file just like I explained in post 4 of coursework 2. Once the request passes the verification that it's an authorised one, a function gets called which updates the user's record with the latest score.
function saveScore($userID, $score){
$updateScoreSQL = "UPDATE users SET SCORE = ".$score.", LAST_BEAT_BY='' WHERE USER_NAME = '".$userID."'";
$result = execute($updateScoreSQL);
return $result;
}
This function returns the a boolean which states whether the update was a success or not. If the update was successful the user gets redirected once more to a page called 'scoreBoard.php'
The Score Board:
<?php
$rowCount = 0;
$result = execute("SELECT USER_NAME, USER_FULL_NAME, SCORE FROM users ORDER BY SCORE DESC, DATE_JOINED");
//loop through all the returned records and create a table row for each
while ($row = mysql_fetch_array($result, MYSQLI_ASSOC)) {
$rowCount = $rowCount + 1;
if ($row['USER_NAME'] == $_SESSION['userID']) {
//Use the echo to output HTML code with the retrieved data
echo "<tr>";
echo "<td align=\"center\" style=\"color: #FF0000\">" . $rowCount . "</td>";
echo "<td align=\"center\" style=\"color: #FF0000\">" . $row['USER_FULL_NAME'] . "</td>";
echo "<td align=\"center\" style=\"color: #FF0000\">" . $row['SCORE'] . "</td>";
echo "</tr>";
} else {
//Use the echo to output HTML code with the retrieved data
echo "<tr>";
echo "<td align=\"center\">" . $rowCount . "</td>";
echo "<td align=\"center\">" . $row['USER_FULL_NAME'] . "</td>";
echo "<td align=\"center\">" . $row['SCORE'] . "</td>";
echo "</tr>";
}
}
?>
Once this page is requested, before sending it to the client-side, PHP code is run on the server, which queries for all the names and their respective score and outputs the appropriate HTML code to build dynamic table rows in order to create the score board. A small touch I decided to include is a check for the current user's record and highlight it in red font. The screen shot below illustrates this score board.
Notifications Function I decided I wanted to fuel up a little bit the competitiveness between the players, therefore I wanted to display a notification upon logging in, which tells the user if a player beat his last score while he/she was away. In the previous section I already mentioned where I am storing this value in the table and how I am retrieving it, so I am going to skip that part and move on to when I populate this value and display the notification.
Keeping track of who beat who's latest score: I previously said that, once a user clicks on 'End Game' his/her score is saved and the score board is displayed, well...I what I didn't say is that between those two actions lies something else. After saving the user's score an IF statement checks if the user's original score, stored in 'origScore' which I already mentioned, is less that the new score. If this is the case, I call a function named 'updateBeatenUsers()' which updates all the user records which had their score beaten by this player, with the player's full name in the Last_Beat_By field.
function updateBeatenUsers($userName, $origScore, $newScore){
$beatenSQL = "UPDATE users SET LAST_BEAT_BY = '".$userName."' WHERE SCORE >= ".$origScore." AND SCORE < ".$newScore."";
$result = execute($beatenSQL);
return $result;
}
Displaying the Notification Now that I am keeping track of who is beating who's score, all I need to do is notify the user on first login. This part is quite easy as once the user is redirected to the game page I have a variable representing the Last_Beat_Value (I explained this in the "Score Keeping with JavaScript" section), therefore its a simple matter of checking whether or not the variable contains a value and if so, display it in a JavaScript alert box like so:
After this, I reset the user's Last_Beat_By field back to null during the saving of the score so that this message will not get displayed the second time the user logs on.
Conclusion
So know, that's the last of this coursework, I must say that its been quite a learning curve but I enjoyed it as I got an exposure over a range of web technologies and managed to create a simple game with a social aspect, which by the way I could host online and have my friends join in!
I hope that my experience was of some use for you who read these blog posts and I would like to say, feel free to comment on my work.
Now, if you excuse me...I've got another round of paper toss to attend to, see you!!
Hi there, I'm currently working full blast on coursework 2 and I have finished implementing and testing the 'Sign Up' and 'Remember Me' functions which I had mentioned in my third post on this subject. Therefore I will cover these two function in today's post.
Sign Up Function Lest start off with taking into consideration new joiners who don't yet have a profile, hence don't have any login details to access the game. For this I created another page with the required fields the user must fill in and it looks something like this:
Sign Up Form
It's not the prettiest interface, but I'm not really giving much attention to eye candy as I am more interested in the functionality aspect of this project. This situation reminds me of an infographic I saw a while back so I decided to include it in this post :)
Designers VS Developers
So, back to the sign up screen. Validation is pretty much handled the same way as in the login screen, apart from comparing the two password fields to make sure they are the same, therefore I will not go into detail again and stick to what is most interesting.
In this form the user is required to insert a User Login which is essential for it to be unique as he/she will use this as part of their login details. But what if the new user coincidently inputs a user login which is already taken?
I address this issue once the user clicks on the create button, which I will now explain.
Once the create button is clicked a JavaScript function which validates the user input is called and if the validation is a success, this function will call another function named 'redirect()'. Yes you guessed it, this function does the same thing as the one I described in my previous post, but instead sends the full name, user login and the first password field values to another PHP page which I've named 'createNewUser()'.
createNewUser.php:
<?php
session_start();
include 'DBConnections.php';
if (isset($_POST['fullName']) && isset($_POST['userID']) && isset($_POST['password'])) {
$UserID = strtolower($_POST['userID']);
//check if passed userID is available
if (mysql_num_rows(checkUserIDAvailability($UserID)) == 0) {//available
//create new user
$createUserSQL = "INSERT INTO users (USER_FULL_NAME,USER_NAME,USER_PASSWORD) VALUES('" . $_POST['fullName'] . "','" . $UserID . "','" . $_POST['password'] . "')";
if (execute($createUserSQL)) {//executes the insert and if true is returned, continues
//stores user's related data in session variables
$_SESSION['userName'] = $_POST['fullName'];
$_SESSION['highScore'] = "0";//by default this is always zero
$_SESSION['lastBeatenBy'] = "";
$_SESSION['userID'] = $UserID;
$_SESSION['Authenticated'] = "yes";
//redirects to paper toss
header("Location: PaperToss/paperToss.php");
}
} else {// not available
$_SESSION['error'] = "This User Login is already taken, please input another one";
$_SESSION['fullName'] = $_POST['fullName'];
header("Location: signUp.php"); //redirects to signUp
}
} else {
header("Location: signUp.php"); //redirects to signUp
}
function checkUserIDAvailability($UserID) {
$result = execute("SELECT * FROM USERS WHERE USER_NAME = '" . $UserID . "'");
return $result;
}
?>
Code Breakdown: As soon as this page is requested, it it makes sure that the session is started and includes the DBConnections.php file I created in my third post on this subject. Then it immediately verifies that the required variables have been posted. Otherwise this request must have been made manually, not via the create button, so it redirects to the sign up page.
If all the variables have been posted, it moves on the check if the user login is available. This is done by calling the function 'checkUserIDAvailability()' which can be seen at the lower end of the code above. This function makes use of the DBConnections.php 'execute()' function and queries for a record from the users table which has the same user login ($UserID) value. The returned resultset is then stored in '$result' and returns it to the calling statement:
function checkUserIDAvailability($UserID) {
if (mysql_num_rows(checkUserIDAvailability($UserID)) == 0) {//available
//create new user record
} else {// not available
//redirect back to sign up
}
The calling statement is placed in the function 'mysql_num_rows()', this function will return the amount of records present in a resultset, therefore if the row count is not zero, the user login must already be taken, otherwise the user login is available.
function checkUserIDAvailability($UserID) {
$result = execute("SELECT * FROM USERS WHERE USER_NAME = '" . $UserID . "'");
return $result;
}
In case the user login supplied is not available, a session variable named 'error' is created and an explanatory message of what happened is stored in this session variable, this will be used by the sign up page to display to the user. Apart from that another session variable named 'fullName' is created and stores the full name the user inputted, this session variable will also be used by the sign up page to populate the Full Name field, so the user will not have to type it again. Finally the user is redirected back to the sign up and the message gets displayed in red:
Sign up page when user login is already taken
On the other hand if the user login is available, crates a new record in the users table with the inputted details:
//create new user
$createUserSQL = "INSERT INTO users (USER_FULL_NAME,USER_NAME,USER_PASSWORD) VALUES('" . $_POST['fullName'] . "','" . $UserID . "','" . $_POST['password'] . "')";
//executes the insert and if true is returned, creates required Session
//variables & redirects to game.
if (execute($createUserSQL)) {
//stores user's related data in session variables
$_SESSION['userName'] = $_POST['fullName'];
$_SESSION['highScore'] = "0";//by default this is always zero
$_SESSION['lastBeatenBy'] = "";
$_SESSION['userID'] = $UserID;
$_SESSION['Authenticated'] = "yes";
//redirects to paper toss
header("Location: PaperToss/paperToss.php");
}
After executing the statement, checks if the insert was a success. If so the requires session variables are created and the user is redirected to the game.
Remember Me Function So, up till now I have only used Session variables and as I have stated before, these are temporary. Therefore to implement a Remember Me function I had to use Cookie variables, as these will be stored on the user's machine and sent along with the request when the user visits my game. To implement the use of cookies I made the authentication.php page receive an extra variable for the checkbox element. Once a user is authenticated, if the checkbox value is equal to true I create two cookie variables, one for the login and one for the password and set their value accordingly.
In the index page (i.e. - the login page), I added a check using PHP code to populate the user login and password fields if the above cookies are sent to the server side:
<?php
//if the user password is set in a cookie, populate the Password field
echo "<input type=\"password\" name=\"password\" title=\"Password\"value=\"";
if (isset($_COOKIE['UserPW'])) {
echo $_COOKIE['UserPW'];
}
echo "\"/>";
?>
Paper Toss Game Progress So now, as a recap, my paper tossing game has a fully functional user sign up and login with remember me functionality, thus the task of transforming coursework 1 into a social networking game is taking shape. By the way do you remember in my previous posts I mentioned that I gave my game a nice background of a cheering crowd? Well I got in touch with the owner of that image to request permission to use it and, well...he charged me $49 for it. Unfortunately I am not ready to pay that sum of money for a detail of such little importance, therefore to respect others property I changed the background image to an un-copyrighted image, so now it looks like this: