friiks
Mar 18 2007, 08:30 PM
Hey! Maybe you've seen my other tutorials...or my signature.. Anyways I'm going to show you how to make a system so users of your site could register accounts and you could have protected - user only - pages on your site  Ok, so we start by creating a config.php file. CODE <?php
$dbhost = 'database host'; $dbname = 'database name'; $dbusername = 'database username'; $dbuserpass = 'database password'; mysql_connect ($dbhost, $dbusername, $dbuserpass); mysql_select_db($dbname) or die('Cannot select database'); ?> Fill in the values of your host and upload it. Here are querie to run in PHPmyadmin SQL CREATE TABLE `users` ( `id` INT( 11 ) NOT NULL AUTO_INCREMENT , `username` VARCHAR( 255 ) NOT NULL , `password` VARCHAR( 255 ) NOT NULL , PRIMARY KEY ( `id` ) ) TYPE = MYISAM ; Next, lets create index.php. CODE <?php //start the session so you would stay logged in //always must be on top session_start(); //include config.php file include('config.php'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> <head> <title>The site</title> </head> <body> <center><a href="?p=idx">Home</a> - <a href="?p=page">Protected page</a> <?php $p=$_GET['p']; //see my ?id= browsing tutorial switch($p){ default: //if user isn't logged in lets show him the log in form if(!isset($_SESSION['username'])){ ?> <form action='login.php' method='POST'> Username: <input type='text' name='username'><br> Password: <input type='password' name='password'><br> <input name="login" type="submit" value="Submit"><br> Not <a href="register.php">registered</a>? </form> <?} else{ //$_SESSION['username'] = the current users //username. It will be echoed like "Hi, user!" echo "<br><br>Hi, ".$_SESSION['username']."!"; echo "<a href='logout.php'>Log out</a>";} break; case 'page': //you can use it like this or use include() if(!isset($_SESSION['username'])){ echo '<br><br>Log in to see this page!';}else{ echo '<br><br>Only user who is logged in can see this!..and you see this so this means you are logged in;]'; } } ?> </center> </body> </html> You see the explanations in the code. Now we need a file that will log the user in, right? Right! Create a file called login.phpCODE <?php //start session and include conf... session_start(); include'config.php'; //get the variables from form and adding some little security $submit=$_POST['login']; $username = mysql_real_escape_string(strip_tags(htmlspecialchars($_POST['username']))); $password = md5($_POST['password']); //if submit button is pressed if ($submit){ if((!$username) || (!$password) || ($username=='') || ($password=='')){ header("Refresh: 2;".$_SERVER['HTTP_REFERER']); echo'<center>Please enter both - username and password!</center>'; } //lets see if the user exists by making a query which selects //submitted username and password from the database //and the we use mysql_num_rows() to count the results returned //if there is a user with a username and password like that $c will be 1 //as it will be counted otherwise it'll stay 0. $sql=mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."' AND `password`= '".$password."'") OR die(mysql_error()); $c=mysql_num_rows($sql); if($c>0){ $r=mysql_fetch_array($sql); //set $_SESSION['username'] to the username from database $_SESSION['username'] = $r['username']; header("Refresh: 2; url=index.php?i=idx"); echo'<center>Login successfull!</center>'; //else, if there werent any records found show an error and //return the user to index. }else{ header("Refresh: 2; url=index.php?i=idx"); echo "<center>You couldn't be logged in!</center>"; }} ?> Ok, so the user is logged in, everything's fine ... but uh-oh...how can user log in if he's not registered ?  make a file called register.phpCODE <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> <head> <title>Register!</title> </head> <body> <form action='<?=$_SERVER['PHP_SELF']?>' method='POST'> Username: <input type='text' name='username'><br> Password: <input type='password' name='password'><br> <input name="register" type="submit" value="Submit"> </form> <?php include('config.php'); ///variables... $submit=$_POST['register']; $username = mysql_real_escape_string(strip_tags(htmlspecialchars($_POST['username']))); $password = md5($_POST['password']); //if button is pressed if($submit){ //if username is not blank..same for pass if(($username) and ($password) and ($username!==NULL) and ($password!==NULL)){ $sql="INSERT INTO `users` (`id`,`username`,`password`) VALUES ('NULL','".$username."','".$password."')"; mysql_query($sql) or die(mysql_error()); echo "Congratulations! You are registered!<br><a href='index.php'>Log in</a>"; } } ?> </body> </html> and the logout.phpCODE <? session_start(); $_SESSION = array(); header("Location: index.php"); ?> I'll add some more explanations later...don't have time now sorry. But you have the code...and if you have questions - ask. Preview
Comment/Reply (w/o sign-up)
Blessed
Mar 22 2007, 03:04 PM
nice tutorial allot of comments i like it
Comment/Reply (w/o sign-up)
Psvertjuh
Mar 22 2007, 06:39 PM
nice tut indeed, really good, maybee i can use it. One question, is it possible, when you already have a forum, that u can make a quick login on your main page so you can login for the forum.. ? <-- bit vague I think?  when u dont get it say it, dont really know how to say it in english
Comment/Reply (w/o sign-up)
friiks
Mar 22 2007, 07:04 PM
Well, I can show you how to make so you can have a little login form in your site that will log you in to forums, but it wont log you into the site... If it's MYbb maybe I could make you a site you can but...yeah..
Comment/Reply (w/o sign-up)
Unholy Prayer
Apr 1 2007, 10:41 PM
Not a bad code. Could be very useful to the users that are new to PHP.
Comment/Reply (w/o sign-up)
Imtay22
Apr 13 2007, 06:00 PM
In register.php- QUOTE <form action='<?=$_SERVER['PHP_SELF']?>' method='POST'> Could i change the form action to register.php, and make the php code register.php and the HTML code to index.php?id=register? I think that would work... But just checking first.
Comment/Reply (w/o sign-up)
jlhaslip
Apr 13 2007, 06:44 PM
QUOTE <form action='<?=$_SERVER['PHP_SELF']?>' method='POST'> Php replaces the $_SERVER['PHP_SELF'] with register.php, so that would not be required. And I think keeping the register script separate from the index.php is a good thing. It modularizes the code so that the Index page is cleaner and the register script is separate, so any changes to it are easier to figure. Just my take on it. You would need to adjust the index page to cause the register script to be called if you make the changes you are considering.
Comment/Reply (w/o sign-up)
Imtay22
Apr 14 2007, 02:21 PM
Okay thank you Jim. I was just wondering...
Comment/Reply (w/o sign-up)
friiks
Apr 17 2007, 07:36 PM
Thanks, jlh, for the answer, maybe you've noticed I'm here almost never. I told why once already so yeah. I just terminated my account and will be looking at the posts and probably making some new tutorials.
Comment/Reply (w/o sign-up)
JDameron91
Apr 17 2007, 08:28 PM
Ah, nice mate. Comments are great, and the code works awesome. I will be looking forward to seeing more of your tutorials very soon. Can't wait to see one on custom skins or something. XD
Comment/Reply (w/o sign-up)
SonicBlow
May 1 2009, 09:11 AM
nice tut dude it really help me alot!!
Comment/Reply (w/o sign-up)
littlkj5
Apr 28 2009, 08:33 PM
How in the world would I add a photo upload to this?
Comment/Reply (w/o sign-up)
iGuest
Mar 22 2008, 10:10 PM
Great Job!!!
Simple User System
Thank you so much for this tutorial! Not only is it great with many comments, but it actually works!! I went through 2 others, both of which weren't compatible with PHP 4... Which is the only thing my outdated host will allow lol. It seems in perfect working condition! Now all I have to do is add my comment and add a hashing algorithm for security (which I'd advise everyone else do too). Thanks again, this was very helpful, as the comments also helped me with some of the PHP commands I didn't know before :D -Chris -reply by Chris
Comment/Reply (w/o sign-up)
Joanatha
Mar 22 2008, 12:40 AM
This is an awesome tutorial. It is very helpful. I really enjoyed all of the comments on the code. It makes it very easy to understand for me, and I'm a n00b to PhP.
Comment/Reply (w/o sign-up)
iGuest
Mar 20 2008, 06:16 PM
Display First Name of user instead of username
Simple User System
Okay guys what I did was add a couple fields in the register.Php page that asks the user for their first name and last name and stores them in the database as firstname and lastname. What I am trying to do is instead of displaying their username when logged in, is to display their first name they entered when they first registered. I got everything up to the point where it stores their firstname into the database. Could one of you guys tell me how this is possible? It has to be something easy and I just can't get it for the life of me! -question by Matt
Comment/Reply (w/o sign-up)
Similar Topics
Keywords : simple, user, system, php, mysql, driven
- Getting Started With Mysql
creating tables and insert data into them. (2)
User Permission Function [php]
Determining User Permissions (3) There have been several recent request for methods to restrict access to various pages on a web-site
based on User Permissions in sites that have a Login System in place. Here is some code showing one
method to restrict access by providing a sub-set of your site's links based on the User's
permissions. In this demonstration, I have defined a string for each 'level of user'
determining which set(s) of links they can view on your site. Normal MySql procedure would be to
read the User's permission level from a record in the database. For the purpose of ....
Adding Data To A Database And Displaying It Later
Using Forms, PHP and MySQL (1) Requirements: PHP Support MySQL Database access I am going to use a news program as an example.
Ok, first you are going to need to connect to the database. Do so by using the code below. I have
added some comments where you will need to edit to fit your server's specifications. Create a
new file with notepad and call it config.php QUOTE //Change root to your database
account's username $dbusername = "root"; //Add your account's password in between the
quotations $password = " "; //Add the name of the database you are using in between the qu....
Simple Shoutbox
PHP, MySQL driven.. (34) Ok, so I'm going to show you how to create a very basic shoutbox which is driven with PHP and a
MySQL database. So, lets start - open a database management program like PHPMyAdmin and run these
queries. SQL CREATE TABLE `shoutbox` ( `id` INT( 11 ) NOT NULL AUTO_INCREMENT , `name`
VARCHAR( 255 ) NOT NULL , `mail` VARCHAR( 255 ) NOT NULL , `time` VARCHAR( 255 ) NOT NULL ,
`message` TEXT NOT NULL , `ip` VARCHAR( 255 ) NOT NULL , PRIMARY KEY ( `id` ) ) TYPE = MYISAM ;
CREATE TABLE `shoutbox_admin` ( `id` INT( 11 ) NOT NULL AUTO_INCREMENT , `name` VARCHAR( 255....
Cpanel Mysql Database Management
Part 2.1 Of My 7 Part Cpanel Tutorial (6) This tutorial is an extension to my 7 tutorial series about the Cpanel. The 7 different Cpanel
tutorials can be found below. Part 1: E-mail Management Part 2: Useful Site Management Tools
Part 3: Useful Site Management Tools2.1 Part 4: Analysis/Log Files Part 5: Advanced Tools Part
6: PreInstalled Scripts, Extras, and Cpanel Options Part 7: Fantastico Detailed Cpanel
Tutorial Part 2.1: MySQL Management In this tutorial, i will explain how to add, edit, delete
and over-all manage the MySQL Feature in the Cpanel. Creating a MySQL Database 1) ....
Starting Or Stopping Apache And Mysql Server Via Batch File
(0) Hi guys, this is a litte tutorial about how we start and stop the Apache and MySQL in Windows NT
(2000, XP, 2003) via a batch file script. As we know in Windows NT based system Apache and MySQL
installed as Windows Services. So we can stop and start it using NET command. For more information
about DOS command, type HELP at command prompt. I assuming that your MySQL service name is "mysql"
and your Apache (Apache 2.0.x) service name is "apache2". If you want to chek it click Start > Run >
services.msc > OK. Windows IS NOT Case Sensitive. Let's get started!. 1. Open....
Check Referrer To Prevent Linking Yours From Other Sites
Check referrer with Php and Mysql (9) Check Referrer Using Php To Prevent People Linking To Your Downloads From Other Sites Ever
find that found some people are listing items, images and tuts and linking directly to the download
url (those that are like my photoshop tutorial.php?id=0), which is a .php to count the number of
downloads. To prevent this, you can add a piece of code to the download pages that checks which page
referred them to the download page: if it's my domain, it downloads the file normally, if
it's not, it will redirect to my home page instead. Important : Not all browser....
Quiz With Php, But Without Mysql
(3) Ok let`s start! Once I wrote it for school: At first we need questions (php) CODE $form_block =
" Quiz What's The Capital City Of England? How Many Letters Are There In The
Alphabet? WHat's 3+10? "; That takes the form of a form... You can, of
course edit the questions. I will now break that code down and explain the different parts. CODE
The reason that any "s (Double quotes) are shown after a \ (Backwards slash) is becouse the
PHP Parser will spew out errors if you forget to do this. "POST" Means that it will ....
Installing Php + Mysql + Apache + Phpmyadmin On Windows Part 2
Continue the last section which is installing phpMyadmin (0) QUOTE phpMyAdmin lets you control you MySQL database from a web browser. Steps: 1. If you
haven't done so already, download the phpMyAdmin Database Manager - You can download the
software from the phpMyAdmin website. Be sure to download the phpMyAdmin-2.6.2-pl1.zip file. Save
the file on your Windows Desktop. ... ... ... Go to for more info. Post Copied. Member
Banned ....
Searching With Php And Mysql
The easy way :P (2) Searching with PHP and MySQL is pretty easy when you think about it, especially if you're doing
it the simple way (without boolean or whatever) /tongue.gif' border='0'
style='vertical-align:middle' alt='tongue.gif' /> It consists of a few forms, a query and an
output. As I said, simple! CODE \"> The form that you just made
contains a text input that people will type into, the next code will extract the form data and then
search it.. Form processing /wink.gif' border='0' style='vertical-align:middle' alt='wink.gif' />
....
Install Php 5 To Work With Mysql
(1) hi, all php 5 is new to all people a long time( actually, I forget how long...). it introduced a
more object-oriented design to developer. like, access type(public, private, protected), abstract
type(classes that can't create objects), interface support, and more . althrought it is
widerly available, someone still can't get it running with mysql. every time the php is starting
up. a message prompted stated that some xtensions can not be found, and therefore, not loaded. so, I
have written this to help other and newbie get it start quickly. note: thi....
A Nice Mysql Server Check
(4) I made this and its not very hard at all just fill in the info and it willl see if your mysql is up
or down CODE Mysql Connection Test // On this you need to put your host most of
the times localhost username and password. $conncect = mysql_connect ( "host", "Username",
"password" ) or die (" Sorry your server can't connect to your mysql server Check to see you
have put in the Username and password and if this is the 1st time you have got this And it has
worked before That means you need to contact your hoster and tell them my MySql server is....
How To "lock Down" A Os X User Account
Crude but effective way to maintain Macs (1) Here's a quick summary of how one can configure OS X for use in public labs running Panther
(10.3). It should also work with Tiger (10.4) but I dunno. There may be better ways, but this is
quick and cheap: 1. Install OS X fresh, or boot up your new Mac, and set the username to
MacAdmin or the like. This is now the administrator account which users should never touch.
Share this password only with trusted admins authorized to muck with critical systems. 2.
Install all the software you expect anyone to need in the default folders (usually Applicat....
Hiding User Account On Xp
(0) Hopefully someone will find this useful. Ive done this on my machine as well. To a hide an account
to display on the welcome screen of xp here is a nifty way: 1. Open regedit 2. Browse to
Hkey_local_machine> software>microsoft>windows nt>winlogon>special Accounts>Userlist Here you will
see a list of all accounts on XP which are hidden and dont display on welcome screen. Yes XP does
create useless accounts as you see there. 3. Go on the right pane, right click, create a new dword
value with its name as the exact username you want to hide and its value as "0" without t....
Mysql Database Setup
tutorial walk through (1) Post copied. Google cache to source Credits have been adjusted. Setting Up Your MySQL &
phpMyAdmin For The First Time This tutorial will show you how to set up your MySQL and your
phpMyAdmin with ease, regardless of whether you are going to be using PHP Nuke or PHP Nuke
Platinum. The process is still the same. -Log into your CPanel with your User Name and Password.
-Click on MySQL icon -Now, we need to create a database also known as Db , Your User Name will
make up part of the necessary details, but you don't need to do this as it will be done au....
How To: Change An Image When A User Clicks On It
using both php and javascript (12) How To: Change An Image When A User Clicks On It using both php and javascript - a powerful
combination I have seen quite a few how tos offering a method of doing this but none of which
resembled my method of making use of both php and javascript. This code is fairly repetitive and
most of the functions are easy to pick-up if you haven't heard of them before. Here it is...
Create your two images. Call them anything you like, you'd just need to change their filenames
in $imgano $imgayes. In fact with this script you can easily create more than one pair....
Php Dynamic Signatures
Using the GD Module and MySQL (9) PHP Dynamic Signatures using the GD Module After much scowering on the internet to find a
suitable tutorial on this subject, I came up empty-handed. So I was forced to learn it on my own
through trial & error. And since I had discovered a lack of tutorials on this subject, I dediced to
write one! Working Example: Abstract : Using the GD Module of PHP allows a developer
to build custom Images with Dynamic Content. Such content could be the Requesting Users IP Address,
Web-Browser Type, Operating System, even the number of times the user has seen th....
Backing Up And Restoring Mysql Databases
(10) If you're an Administrator on a Forum, you probably know the importance of regular data backups.
My Forum is always being hacked by someone and they always delete our SQL Databases. Well this
tutorial is for all of you who want to protect your data and restore it if necessary! Okay, backing
up your data is the first part. I use Cron Jobs in my cPanel to automate the backup process. Just
use this code for backing up all your SQL Databases: CODE mysqldump -u root -psecret
--all-databases > backup.sql OR if you wish to backup only a single database: CODE ....
Simple Login In Visual Basic 6
user interaction example trough login programm (9) First of all, I am NOT a programmer, this is something my friend taught me. It describes basic
interaction with the user, while showing basic functionality of this simple programm. So, without
further ado, we're off to the tutorial: First of all, start your visual basic, when prompted
for new project, select Standard Exe . Next, we need to open code window, so we can start typing
the program. This can be done in two ways, one is double clicking on the form, or selecting Code
from View menu. If you double clicked on the form, you will see following text: CODE ....
Php/mysql Login/register
Tutorial for login with databases. (4) Start register code. Register.php CODE Username: Email: Pass: Verify
Pass: //Login to your database. Make the fields of course..
mysql_connect("localhost","user","pass"); mysql_select_db("database"); //end //if registering,
check fields. if ($action == register) { if (!$user || !$pass || !$email || !$vpass) { print
"You must fill out all fields."; exit; } $dupe1 = mysql_num_rows(mysql_query("select * from
table where user='$user'")); if ($dupe1 > 0) { print "Someone already has that
username."; exit....
Complete Login And Registration System
doesn't use mysql! (9) kLogin 0.1 QUOTE(readme.txt) Readme file to kLogin 0.1 To use the internet explorer fix:
download the latest IE7 ZIP file
(http://sourceforge.net/project/showfiles.php?group_id=109983&package_id=119707) Extract the ie7
zip file to the root directory of your web server. Example, if you are using a unix/linux server,
it's on "public_html/" or "home/public_html" Open kLogin.php file with your editor and edit the
$info_text or $info_txt variable. Then, extract the kLogin.php file in to the root directory of
your web server also. Just run kShoutBox.php If ....
How To Host Ur Own Site In 2 Mins Php+mysql Needed
(34) QUOTE Run you're own server for testing phpmysql or just to host you're own website or
for you're friends. -needS: a PC that's all 8) - How to ? download : CODE
http://server.paehl.de/apache20.zip : 30 seconds Installing:---> 1 minute
*********************************** Unpack the exe where ever you want. after unpack run
serverinst.exe and change Servername and your e-mail. Start the following files one time:
start_apache.cmd --> start apache as service mysql_start_as_service.cmd --> dito for mysql
mysql_first_start.cmd --> start m....
Shoutbox, Made Easy
PHP+MySQL ShoutBox! Very simple... (17) Just create a PHP file named "kShoutBox.php" CODE /* ******************************
kShoutBox 0.1 ****************************** */ /* ****************************************
This ShoutBox script was created by Juan Karlo Aquino de Guzman DO NOT MODIFY THIS CODE AND
DISTRIBUTING IT WITHOUT ANY PERMISSION. E-MAIL THE AUTHOR FIRST. Email: 01karlo@gmail.com DO NOT
REMOVE THE "POWERED BY". FOR SUGGESTIONS, COMMENTS, ETC, SEND AN EMAIL TO 01karlo@gmail.com
HOPE THAT YOU ENJOY THIS SCRIPT! MY FRIENDSTER: karlo@*BLEEP*it.com ***************....
Clicks Counter
With PHP + MySQL (1) Well, in this tut, I'll show you how to do an simple link counter, with only one count for each
IP and the date when the link were clicked. Just remember, this is only one way to do it. First,
create an mysql database called 'links', with 2 table: first table will be called
'links', with the columns: id, title, ref and clicks. The other one will be 3 columns and
will be called links_info: id, ip and date. Just remember that the columns 'id' of this
second table IS NOT auto-increment. Here is the code of the file which will count the clicks, ....
Complete Login System
With PHP + MYSQL (57) Its an complete login sistem made and tested by me and I think itwill be very usefull for people who
are tryn to learn PHP. First, let's make register.php: CODE include("conn.php"); //
create a file with all the database connections if($do_register){ // if the submit button were
clicked if((!$name) || (!$email) || (!$age) || (!$login) || (!$password) || (!$password2)){ print
"You can't let any fields in blank.\n"; // if the user did not put some field exit; } $name =
stripslashes($name); $email = stripslashes($email); $age = stripslashes($age); $login = s....
A Guide On Webhosting, Php, Mysql, And Phpmyadmin
(0) I thought I'd submit this little guide of mines, after I gave my friend an impromptu
introduction on this. I hope those who are new to PHP and MySQL will fin this usefull. What is
PHP? PHP is a scripting program, you install PHP into your server, BUT, you can only do it if you
have "physical" access to the server, (i.e. - you can close the server, add stuff to the server,
clear the server, remove the server). People who have web hosting accounts CAN NOT install PHP,
because, they only "own" a part of the server. You must be the server administrator in order to ins....
Looking for simple, user, system, php, mysql, driven
|
Searching Video's for simple, user, system, php, mysql, driven
See Also,
|
advertisement
|
|