Jump to content
xisto Community

Frazzman

Members
  • Content Count

    17
  • Joined

  • Last visited

Posts posted by Frazzman


  1. Welcome to my PHP tutorial on how to create a Login script using PHP that connects to a MySQL database and reads usernames and passwords before continuing.

     

    STEP 1 (ONE) - Getting prepared

    First off, you will need to install a program called XAMPP. You can download it from Here. Just follow their step-by-step tutorial on how to set it up.

    You will need this so you can code in PHP and test it by using phpmyadmin and MySQL.

     

    Now, the program I recommend for coding PHP is Notepad++. This is an epic program that can be used to code many different languages. You can download it from Here.

     

    STEP 2 (TWO) - Setting up the files

    First off, we need to create the files for this tutorial.

     

    Go ahead and open Notepad++ and create 2 new files. Save them both in the same file, one with the name "index.php" and "login.php"

     

    STEP 3 (THREE) - The Login Form

    Now we need to make the login form for our login script.

     

    Open up the index.php and enter this code.

     

    <form action='login.php' method='POST'>

    This will start off the form. action='' means what file this form will be relying on for input data, so we put login.php as our action.

    The method can either be POST or GET. POST means that a user will be inputting data to send a request, which in this case will be our action.

     

    Now put this underneath

    Username:<br />
    <input type='text' name='username' /><br />
    Password:<br />
    <input type='password' name='password' /><br />
    <input type='submit' value='Login' />
    </form>

    Username: is just the text in front of the textbox

    The input is an option for some sort of input for the user. type='text' means is will be a normal textbox for a user to type something. name='username' is just the name of the textbox. This is crucial for this tutorial.

     

    <br /> is just a line break, meaning the next line of coding will be placed on a separate line.

     

    input type='password' means this will be a textbox for a password. When a user types something in, it will show up as Dots or *.

    The name is password. Once again, this is crucial.

     

    input type='submit' is the code for a button. value='Login' is the text that will be shown on the buttton.

     

    That is the index.php done, now to the next step.

     

    STEP 4 (FOUR) - Starting the Login Script and creating our database

    Open up the "login.php"

     

    First, we need to put the PHP tags for our PHP code to work.

    <?php
    
    ?>

    Our coding will go in between these tags.

     

    We are going to start off by defining 2 (two) variables. Our Username and password. Enter this code:

    $username = $_POST['username'];
    $password = $_POST['password'];

    $username and $password are the 2 (two) variables we are going to be defining.

    $_POST['username'] and $_POST['password'] is what our variable is. $_POST is the method we put in our login form, which was POST.

    The ['username'] and ['password'] is the name of those textboxes in our login form. The login will be reading off of those textboxes.

     

    Now after that, type this:

    if ($username&&$password) {
    
    }
    else {
    die("Error: Please enter a username AND password!"); }

    This means, is the 2 (two) textboxes have something in them, then it will continue on with the script between the { and }. If 1 (one) or both are empty, then the script will terminate itself, showing an error of "Error: Please enter a username AND password!". That is our else statement.

     

    Now we need to create an SQL database for the next step. If you did what I said before and installed XAMPP, go to your browser and in the address bar, type:

    LOCALHOST/

    NOTE: Make sure your Apache and MySQL services are running! Enable them in your XAMPP control panel.

     

    When you are at the XAMPP main screen, select phpMyAdmin

    In the text area where it says Create new database, type whatever name you want your database and click Create. Don't worry about the other stuff.

     

    It will take you to a new screen, saying it created the database.

    In the text field where it says Create new table..., Name the table accounts and put the number of fields as 3 (three).

     

    In the first field, put the name as id and the type as INT. Go down to where it says index and choose PRIMARY. Also tick the box for AUTO_INCREMENT. This means the id will start at 0 or 1 and continue everytime a new user is made.

    In the second field, name it username and the type and VARCHAR, set the max length to 25.

    For the third field, name it password and the type as VARCHAR. Again, set the max length to 25.

    Now click Save down the bottom.

     

    Now that we got the database out the way, we need to make a username and password for it.

    Go back to the database you made and at the top of, select the tab that says Privileges. Select New User and choose a username and password for the database. Make sure you have ALL privileges.

     

    Ok, that is phpMyAdmin out the way. Still a lot more to go (:

     

    STEP 5 (FIVE) - The rest of the Login Script.

    In between the { and } type:

    $connect = mysql_connect("Host","DB Username","DB Password") or die("Couldn't connect");
    mysql_select_db("Name of the database here") or die("Couldn't find database");

    In this, we are defining the variable $connect. This will execute a MySQL command to connect to the databse, mysql_connect. In the brackets, change the Host to your MySQL host. In this case, it would be localhost. DB Username and DB password is the user you created for the privileges to the database. If it cannot connect, it will terminate the script with the message "Couldn't connect".

    If all is good, it will execute a MySQL command to select a database, mysql_select_db. In the brackets, type the name of the database you created.

    Make sure you keep the ""! If it can't find the database, it will terminate.

     

    After this we are going to perform a MySQL query. Type this after the above code.

    $query = mysql_query("SELECT * FROM accounts WHERE username='$username'");

    $query is the variable we are defining.

    mysql_query is the command to execute a query. In the brackets it says "SELECT * FROM accounts WHERE username='$username'", this means it will search every row in the table accounts for a username $username which was the variable we defined at the top of the script for our username text box.

     

    After that, type:

    $numrows = mysql_num_rows($query);
    if ($numrows!=0) {
    
    }
    else {
    die("That user does not exist!"); }

    We are defining the variable $numrows to scourer through the table, mysql_num_rows, for the username you entered for the $query variable.

    If it finds a username that is the same as the one you entered, it will perform the next step. If it does not find it, it will terminate the script with a message That user does not exist!.

     

    Now, in between the { and }, enter:

    while ($row = mysql_fetch_assoc($query)) {
    $dbusername = $row['username'];
    $dbpassword = $row['password'];	
    }

    This one is pretty much defining a variable associated with one of the columns from your database. In this case, we are defining $dbusername and the row username in your table and $dbpassword as the row password in your table.

     

    After that, type:

    if ($username==$dbusername&&$password==$dbpassword) {
    header( 'Location: Your location here');
    $_SESSION['username']=$username;	
    }
    else
    die("Incorrect Password!");

    This will check if the username textbox, $username, matches one of the usernames from the table, $dbusername. It will also make sure on top of that the password textbox, $password, is exactly the same as one of the passwords in the table, $dbpassword.

    If this is true, then it will redirect you to your desired webpage. Change your location here to your desired address,

    It will also make a session. This means we need to go back to the top of the script and after the <?php we need to put:

    session_start();

    I will explain this a little further down.

     

    If this is not true then it will terminate the script.

     

    STEP 6 (SIX) - The session

    Where we put $_SESSION['username']=$username, this will make a session for that username. What this means is:

    -If you make a webpage where you want a user to login, then you would put

    if ($_SESSION['username']){
    
    }
    else {
    }

    In between the { and } you would put the code that the user must be logged in to see, and at the top of the webpage, you must put

    session_start();

     

    STEP 7 (SEVEN) - Testing the Script

    Now, in you phpMyAdmin, make an account in the table accounts to test your script. If all went well, you will be fine (:

     

    You have no idea how long this took me to type up lol. Thanks would be greatly appreciated.


  2. Since I like to write about Indie game design, it is inevitable that, at some point, I must discuss Minecraft. Written by this Swedish guy commonly known as Notch, it emerged overnight to take over the world and sell meeelions of copies. It has had a level of success my games can never ever hope to match, and it's kind of earned it.
    Of course, I could go on, as many others have, about the soul-crushing lack of anything in the game to help anyone actually understand it. Of course, officially, it's still a beta, but it's still super harsh in the early going. Don't try to play it without reading this Newbie FAQ and bookmarking the recipe list, unless you enjoy suffering.

    For the few people who haven't played it yet, Minecraft is usually described as a Lego video game. You start out a guy on a deserted island. You can gather cubes of dirt and wood and stone and use them to build, well, whatever you want. Houses. Castles. Roller coasters. There's no plot, per se. It's a creativity tool and an incredibly addictive one. The game system is very simple, allowing for hilarious mishaps, outlandish creations, and manifestations of mental illness.

    I made a nice two bedroom house for a family of four. There's a wall around it. It's nice.

    But for a no-budget Indie game to sell north of 1.5 million copies? In beta? There is something crazy insane going on here, some sort of true genius. This guy captured lightning in a bottle, with a fairly crude-looking game with no tutorial and a punishingly difficult first ten minutes. I honestly wouldn't have thought it possible. Anyone who cares about game design should look closer and see what this guy did right...

    You Have To Earn What You Get

    If you want to make a house out of 500 blocks of stone, you first have to dig them up. But then you just have an empty house. If you want something nice, like a clock or a golden pillar or a roller coaster, you have to search more and dig deeper. One of the key elements of Minecraft is the personal satisfaction you get from looking at what you built, which comes in part from knowing that you had to spend your time to earn it. And people do spend the time, because ...

    You Get Stuff Fairly Quickly

    The guiding principle behind Minecraft seems to be that you have to earn everything you get (by spending time), but practically everything comes cheaply. The stone to make a fortress can be dug up fairly quickly. The key insight here is that, to give a player self-satisfaction, you do need to charge a price (again, paid in your time), but that price can be very small. As long as there is any price at all, even a low one, the player can feel pride in his or her creation.

    There Is Danger

    On normal difficulty or higher, monsters can spawn anywhere where it is dark. And these aren't candyass, meaningless trash monsters, either. They are skeleton archers that can kill you dead before you even figure out where they are and exploding ambulatory suicide cacti that spend one second hissing in warning before they pop, killing you and destroying everything nearby.

    Minecraft was never meant to be a shooter. You can make weapons and armor, but they're tough to make and wear out quickly. The vast majority of foes should simply be avoided. The point of the game is not kicking *bottom* but achieving safety.

    Now, to be clear, the danger element is not necessary. Plenty of players switch the game to Peaceful difficulty and never face a worse threat than falling into lava. But for players like me, who need some sort of story element or immediate goal to get into a game, the pressing need to make a Safe Place is a perfect way to feel involved. And, once the game gets you actually playing, it becomes much easier to answer the most difficulty question any creativity toy poses: "I can make anything I want, but what do I want to make?"

    But Not Too Much

    Minecraft is dangerous, but not too dangerous. Torches are easy to make, they never go out (for now, see below), and monsters never spawn in lit areas. It is easy to make an enclosed place where monsters will never jump you. And yet, if you ever walk outside or if you accidentally leave a dark spot in your house, the danger comes pouring back in.

    And, much in the same way that only a tiny amount of effort gives a player pride of ownership, the mere awareness of danger is enough to keep things interesting. Once, when I was modifying my house, I forgot to place a torch in one of the rooms. It gets dark, I go to bed, a zombie spawns in that room, and, when I wake up, it's eating my face.

    No matter how safe you make things, a moment of complacency can always kill you. The constant presence of danger can make anything more interesting, even stacking little cubes.

    The Game Model Is Incredibly Forgiving

    Game designers frequently want to make things too hard for players. There is a constant fear that someone, somewhere, is getting away with something. For example, it must have been very tempting to have Minecraft have a real physics model. Make your wood building too big or unbalanced, and watch as it crumbles before your eyes. Hah! Take that, you dumb gamer!

    Minecraft isn't like that. It's a creativity tool. It strongly resists the desire to be hardass about what you can build and gets out of the way as much as possible. Want your giant stone castle to hang in midair? Sure! The game's job is simply to let you create.

    With one limitation. Fire is merciless. Try to burn up the patches of brush in front of hour house and I promise, within five minutes, your happy green island will look like Mordor.

    And the Developer Is Very Generous

    For the amount of entertainment the game can provide, it's amazingly cheap. Around twenty bucks for the beta, and that comes with all future patches. No DRM. No recurring fees. One account serves as many machines as you want to use it on. And once, when their ordering servers were down, Notch simply made the game free.

    This is just one example of someone becoming very successful by making something really cheap. See also: Humble Indie Bundle.

    But We're Just At the Beginning

    One of my favorite things about Minecraft is that it's a work in progress. We can watch the developer's tightrope act in real time, and they might still screw everything up!

    For example, they have been flirting for a while with making torches go out. You would have to spend time running around with flint and steel relighting torches, or areas will go dark and "Oh God! Zombies! My face! Aaaahhhh!" This would be a huge change in the nature of the game, introducing a new activity that would pull lots of time away from the core activity: gathering materials and doing stuff with them. This change has been put off for a while, though, so they may have had the wisdom to rethink it.

    (In fact, watch for any change that will heavily alter the proportion of time the player spends on various activities - digging, building, etc. These are the changes that will muck up the game.)

    They are also considering adding Hardcore mode, where if you die your world is gone for good. I suppose this is a good change, since it is optional and some people love pain.

    But I suspect that their design instincts are pretty good. Instead of making torches go out, they are adding cute wolf pets. Genius. My daughters will die of happiness.

    So Try It

    If you love Indie games, try this one. It takes some work to get into it, but it is a worthwhile exercise just too see how much innovation small developers are capable of. I am on the record as saying that small Indies aren't as innovative as people give them credit for. This is one case when I've been very happy to be proved wrong.



  3. I love vbulletin best piece of forum software going and I'm extremely skilled in using it, the price is 100% worth it as you can make that back via donations etc anyway. Also there are bulled versions for those who cannot afford it, I know a site with nulled bulletin and it releases loads of mods to therefore a great substitue and is identical to bulletin as it is vbulletin hope I helpedd


  4. I'm actually considering turning this in to an open-source project at the end of the tutorial. Try and gather a developing community to create a free text-based rpg system which is easy to use and feature rich and a large module database so users can create a completely customised game. That way people may turn to using this instead of being ripped off and buying something like mccodes. No doubt they overcharge for a rather limited engine.
    Open-source is always the best way.

    I vote bring back the site it was one of the most helpful things ever i would really appreciate the files and all that, thanks.

  5. Hi there, I've had some experience in game creation in the past so I'll give you a few good starting points. For people who are just starting out, there is a piece of software out there called Realm Crafter.
    This natty piece of software is built around the blizzard engine, the same as World of Warcraft. It creates a point-and-click environment for creating your new realm and offers many prefabs and entities for you to insert in to your game. The next release of realm crafter has a lot of exciting new features as well, including hosting multiple servers to spread out bandwidth and cpu consumption.

    Once you have managed to get to grips with realm crafter and are confident in your abilities to use it (it will take some time but don't worry, it'll be well worth the investment) then you can move on to learning how to create your own content for your game. This will require you to learn about 3D graphics design. An amazing program to start learning this on would definately have to be Milkshape. It is very easy to use and great for learning how to design objects in a 3D environment. Milkshape isn't capable of creating high poly entities though although I wouldn't expect you to be able to create high poly objects without at least a years study. (Polys btw are the little points that create the frame of a 3D object, you might have noticed older 3D graphics being fairly blocky, each point on those blocky graphics are a poly).

    Don't go jumping in to image design too early, familiarise yourself with 3D design before applying textures to your images. Then you can start to learn how to create your textures. A great little app for that would be Jasc Paint Shop Pro although it has now been absorbed in to Corel. It's a bit simpler than using photoshop but with the same advanced features. It might take a little time to properly get to grips with shading your textures to match your 3D object, but trust me you will get there.

    Now you can use the software to construct and configure your game, create 3D objects and characters to import in to your game and create great graphics to apply them.

    It's only a rough guide but hopefully it is enough to get you started. If you need any more help though then feel free to ask as well.


    Just the information i was looking for thanks alot i will follow this like theres no tommorow hopefully i can work with these engines well and make a cool looking mmorpg ;) thanks.
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.