HmmZ
Members-
Content Count
365 -
Joined
-
Last visited
Everything posted by HmmZ
-
Php Simple Login Tutorial Learn how to make a simple login
HmmZ posted a topic in General Discussion
I have been quite busy lately, trying to design and code my site (far from done XD). And after having learned how to make a simple login, I will try to write my own tutorial, for you the tutorial Step 1: The first step in designing a member system is to plan out exactly what you need. A common impulse among programmers is to jump right in and start coding. I'll be honest and admit that I'm guilty of this more so than anyone. However, since I'm in control of this conversation (yes!), you'll have it all planned out by reading through this before you even see any code. What will you need to start? First of all, you need a server that supports a CGI or Server-side language. For this tutorial, it's PHP. I won't be directing any attention to any other language at this time, so although the concepts will be similar, the code will be entirely different than something you might use in Perl or ASP. As a side note, it is possible to perform a member system simply using JavaScript, but it would not be remotely secure because JavaScript is client-side (thus able to be viewed by anyone), and even if you had a one-way encryption script it would not be feasible because of the pain of hard-coding usernames and encrypted passwords into the HTML document. Second, at least for our purposes, you need a database. Preferably MySQL. PHP and MySQL go hand-in-hand, so a lot of servers tend to match the two up. Thus, since we're talking PHP, we may as well talk MySQL. Third, you will need 4 blank PHP web pages entitled: register.php, login.php, members.php, and logout.php. After you have these pages created and open, we're ready to start. Step 2: Database If we want to design a members system, we'll need a database. So all we need to do in this step is to create the table we will use to manage the user's login information. Note that the schema we use here is quite simple, and is only simplified to help you see how it works. Name the table "dbUsers." It will need 4 fields:[I]Name Type Addition[/I]id int(10) Primary Key, AUTO_INCREMENTusername varchar(16) Uniquepassword char(16) email varchar(25) Once you've made the database table, you're ready to design and code the registration page. Create a File to Connect to your Database Create a new file and name it dbConfig.php. This file will contain the PHP code that will connect to the MySQL database, and select the correct database. Make sure you have added users to your MySQL database with read/write or admin access, then place this type of code into the dbConfig.php file: <?// Replace the variable values below// with your specific database information.$host = "localhost";$user = "UserName";$pass = "Password";$db = "dbName";// This part sets up the connection to the // database (so you don't need to reopen the connection// again on the same page).$ms = mysql_pconnect($host, $user, $pass);if ( !$ms ) { echo "Error connecting to database.\n"; }// Then you need to make sure the database you want// is selected.mysql_select_db($db);?> Step 3: Register register.php On your registration page, you need to create a web form that will allow the user to plugin a username, password, and their e-mail address. Then, also on your page, add code that runs only when information has been passed via the form. Finally, display a "Registration Successful!" message to the user. <?php // dbConfig.php is a file that contains your // database connection information. This // tutorial assumes a connection is made from // this existing file. include ("dbConfig.php");//Input vaildation and the dbase code if ( $_GET["op"] == "reg" ) { $bInputFlag = false; foreach ( $_POST as $field ) { if ($field == "") { $bInputFlag = false; } else { $bInputFlag = true; } } // If we had problems with the input, exit with error if ($bInputFlag == false) { die( "Problem with your registration info. " ."Please go back and try again."); } // Fields are clear, add user to database // Setup query $q = "INSERT INTO `dbUsers` (`username`,`password`,`email`) " ."VALUES ('".$_POST["username"]."', " ."PASSWORD('".$_POST["password"]."'), " ."'".$_POST["email"]."')"; // Run query $r = mysql_query($q); // Make sure query inserted user successfully if ( !mysql_insert_id() ) { die("Error: User not added to database."); } else { // Redirect to thank you page. Header("Location: register.php?op=thanks"); } } // end if//The thank you page elseif ( $_GET["op"] == "thanks" ) { echo "<h2>Thanks for registering!</h2>"; } //The web form for input ability else { echo "<form action=\"?op=reg\" method=\"POST\">\n"; echo "Username: <input name=\"username\" MAXLENGTH=\"16\"><br />\n"; echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"><br />\n"; echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"><br />\n"; echo "<input type=\"submit\">\n"; echo "</form>\n"; } // EOF ?> Step 4: Login login.php Now in PHP, first we need to check the username and password against the information stored in the database. Since when the user registered, we encrypted their password using the MySQL PASSWORD() function, we re-encrypt the password the user supplied in the login form and cross-check this with the existing value in the dBase. If login information is O.K., then we need to use sessions to store the user's ID so they can access member-only content. <?php session_start(); // dBase file include "dbConfig.php"; if ($_GET["op"] == "login") { if (!$_POST["username"] || !$_POST["password"]) { die("You need to provide a username and password."); } // Create query $q = "SELECT * FROM `dbUsers` " ."WHERE `username`='".$_POST["username"]."' " ."AND `password`=PASSWORD('".$_POST["password"]."') " ."LIMIT 1"; // Run query $r = mysql_query($q); if ( $obj = @mysql_fetch_object($r) ) { // Login good, create session variables $_SESSION["valid_id"] = $obj->id; $_SESSION["valid_user"] = $_POST["username"]; $_SESSION["valid_time"] = time(); // Redirect to member page Header("Location: members.php"); } else { // Login not successful die("Sorry, could not log you in. Wrong login information."); } } else {//If all went right the Web form appears and users can log in echo "<form action=\"?op=login\" method=\"POST\">"; echo "Username: <input name=\"username\" size=\"15\"><br />"; echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />"; echo "<input type=\"submit\" value=\"Login\">"; echo "</form>"; } ?> Step 5: Members Area members.php Now that the user has logged in successfully, and has his id, username, and login stored in session variables, we can start working with member-only content. A major thing to remember is that any page you want to carry session data over to you must declare a session_start(); at the top of your code. <?phpsession_start();if (!$_SESSION["valid_user"]) { // User not logged in, redirect to login page Header("Location: login.php"); }// Member only content// ...// ...// ...// Display Member informationecho "<p>User ID: " . $_SESSION["valid_id"];echo "<p>Username: " . $_SESSION["valid_user"];echo "<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]);// Display logout linkecho "<p><a href=\"logout.php\">Click here to logout!</a></p>";?> Step 6: Logout logout.php Ah, although it would be nice if our user's never left our web sites, we should give them to opportunity to log out and destroy the session variables if they so choose. It's quite easy to do, and you can just copy and paste this one. <?phpsession_start();session_unset();session_destroy();// Logged out, return home.Header("Location: index.php");?> That's about it!. I used many simple examples hoping that you will learn how the internal systems work so you can expand on them and design a system that's just right for your needs. Have fun! -
Well, I'm not a great flash programmer, but it's only that you mentioned it's flash, else I wouldnt even notice :DSo could you explain how you made it so you can edit your flash news in a simple text box? Did you use the php-news system from Whyme?Anywayz, love the site, needs some editing. And the blog looks nice
-
Mobious,Advising him to make his own webserver using the dynamic duo, is actually a bad advice, all the guy wants right now is learn PHP, he never mentioned MySQL (even though it's its best partner). Letting him set up his own webserver will only cause confusion, without enough knowledge of functions. For a beginner, databases are just extending the difficulty of PHP, because, basically, you don't need MySQL right away to start with PHP, PHP has enough features to use without needing dbs.
-
Err,It may be an addition ATI added to the card, or and extended sponsor feature by the creators of Doom 3/ATI. But Doom3 has very few or even nothing to do with ATIs latest card.Games like Doom 3 and Half Life 2 just give people the reason to buy excessive graphics cards. And in the other way, without game makers of doom 3 and hf2, ATI wouldn't be even creating these kinda cards in mass production, Gamers buy it for their "super" games. But the real and optimal use of these kind of graphics cards is pretty much leftout, doom 3 and hf2 can easily be played with a much cheaper way of graphics cards (such as a good double AGP cards).The people that buy ATIs x850xt also have their system configured with PCI-Express, wich is, at the moment, an seriously expensive expansion of the lesser Game monsters. At the moment, AGP x8 is more then enough for ANY game available. PCI-Express becomes valuable in maybe a year, maybe even 2 years, by that time they are more then pricable if not even taken from the market, because the Graphic Card industry isn't holding back, there is a large enough quantity of people who buy these excessive cards.
-
Hard Drive Problems.. Need Help Hmm I am wondering if something is possi
HmmZ replied to spawn_syxx9's topic in Software
Yes you can do that-Put a windows 98se floppydisk in your floppydrive[Download the bootdisk files from http://www.bootdisk.com/ and put it on a floppy]-reboot your computer-It will automatically read the floppy and start MS-DOS Prompt-Insert your windows XP Pro/Home disc-Go to your discdrive (command= cd D:/ (D is the default cd-rom/dvd drive))[Result: D:/]-When you have D:/ (instead of A:/) type the following command: cd i386[Result: D:/I386]-Type the following command then: winnt[Result: Starts Windows XP MSDOS setup]-Then follow the screens, once you see repair/restore (not sure), use that option-I'm not completely sure, but that should most likely fix the problem, Windows Repair will find the corrupted file, and repair it -
The url you provided isn't a great webbie, the layout pretty much sucks and the content is not to mention...in comparison with big sites like hotscripts.comUnlike your url, hotscripts has a great and active community where your questions will be answered within a day or less. The collection of scripts of course adds to their reputation. Codegrrl has only a handful of scripts but surprisingly alot of posts (40k+) wich does mean this site isn't a just started community. All there is to do is change the layout/theme/logo/number of scripts...Do you have an hour or 2?
-
Great tutorial, just what I was looking for, but I do have 1 question, is the news/edit/index.php safe enough to let other users use it? If it is, I can turn it easily into a review submission system, wich would be great I'm asking this since you point out that you (the admin) can go there and easily submit news, not clearly stating that users could go there too (of course, news is usually not formatted by users themself, would be a chaos )
-
What they said :DYou could compare it with nearly any e-mail provider, and see it is superior in space and speed. Hotmail for example, only offers 2mb free, and since there are probably billions of hotmail accounts now, it got slow, the many buttons, the many advertising pretty much destroyed hotmail, I for one have 1 hotmail account but almost never visit it again, because it's slow to load.Gmail on the other hand, offers a complete page just for you and your inbox, 1 banner to the side with no graphics is all there is. Gmail used nearly no buttons, and that's whats making it fast as hell(Yea, send me a PM, i also got about 40 left)
-
I haven't been that long in the RPG games, but since i've found they are fantastic games, i've started crawling around the net searching for great (and free) online games (MMORPGs). So far, I've tried Priston Tale, Fairyland, Anarchy Online, KALonline, Xiah, Runescape, MU Online, Maplestory, GunBound and my latest find is ASDF Game, a pretty original game where you race with a hoverboard against a max of 6 other hoverboarders, leveling, buying items, rare items to find and yes, they even have the marriage feature ( ) Weird but fun to play game :DAll other games became boring after a while, I have yet to try Diablo, don't fel like starting there while it's a community existing for many years (hate to be a newbie )
-
The fastest way you learn is through practise, practise and more practise. Just go create a small website containing php pages, and php code. I'm at the same level as you probably, only i'm 6 years older .Right now I'm actually trying to figure out the member feature (register/login/logout/members online/etc..) and it's a tough one, but with the many decent php sources on the web, it can't take long to figure out, I can offer you a book in PDF format, but you'll have to PM for that. The book is called PHP/MySQL for dummies, good to understand, well explained with pictures and codes and you'll learn many aspects of this dynamic duo.
-
Sony Offers Pizza Feature For Hungry Gamers
HmmZ replied to talbotda13's topic in General Discussion
You'd say it's a convenient feature, but all there is to it is danger. With this feature, a gamer will order a pizza more easily, eventually robbing their wallets. Everquest probably gets a big bunch of sponsor money for this and with a player community of over 330,000, they won't have to be scared to not have any orders each day.This is not an improvement, nor a drawback, it's just something extras to rob the gamers wallets, to my opinion, as you can see, this is an idiotic feature. -
Adriantc,You would be surprised how many people buy such expensive cards, just because they are new, and the people are collecting them. Remember, a beta version of a card is something completely different then a Game's beta version.Personally, I would never buy such expensive cards, if I even had that kinda money () I could spend it on better things in life.With the many improving developments, like PCI-Express, S-ATA and much more. The development in cards, processors and motherboards seem to have gotten a good push in the back, pushing them on the highway of development. But the unfortunate thing about new development are always the costs. The producers still produce low-budget technology, but you can't expect those things to work as good as their newest cards.
-
Talk About Favorite Online Games GunBound is a free, multiplayer game
HmmZ replied to gunbound's topic in Computer Gaming
I've been playing Gunbound for about 2 years now. And I still occasionally play the game. But since the hackers community expanded so widely, I started playing the game lesser. Even though the game experience is still fun, you often encounter hackers who just ruin the whole game.Softnyx, the creators of GunBound, are trying so hard to cut down on this hackers community, but onces they banned 20 IP's, 25IP's come back to hack even more :DWith their latest system (it's not new anymore) nProtect, they have seriously cut down on the hacking, on top of that, they were able to hide the gunbound process in the windows OS taskbar, disabling many hackers to target that process, so their work is getting somewhere