Building an entire membership system can be a tedious, and time-consuming task. Tim Cooper is going to show us how to build the ENTIRE thing in roughly thirty minutes. Rather than using MYSQL as our database, Tim will instead demonstrate an alternate approach: using an XML file. We'll be reviewing PHP, .htaccess files, sessions, and more!
Related Posts
Check out some more great tutorials and articles that you might like
Plus Members
Source Files, Bonus Tutorials and
More for $9 a month for all TUTS+
sites in one subscription.











User Comments
( ADD YOURS )Gareth February 12th
Interesting article: I will always would rather use MySQL though..
( )ThaClown February 12th
Pff… man you are fast!
Alot to learn from this vid, I guess I should first finish the “Diving into PHP” series!
Thanks alot man.
( )M.A.Yoosuf February 12th
ha, its great, but how fat its practical, because its like flat file system
( )Groningen February 12th
Damm nice tutorial, you also worked it out realy fine.
Greetings from the netherlands
( )Eduardo February 12th
I thought nothing could be faster than the speed of light…. I was wrong! LOL
( )Some Funky Dude February 12th
I think this is a great tutorial on using the SimpleXMLElement object
one thing I didn’t understand why preg_replace() was necessary on the username field but not the email input field
( )DKumar M. February 12th
Impressive Tut Cooper… Nice and fast !!
( )Alessandro February 12th
Thank you, maybe it’s not a perfect solution for a login system, but for some other data it can be very useful.
( )Paul Davis February 12th
This is BRILLIANT! O think, the best tutorial I’ve seen on NetTuts, for me anyway.
Thanks Tim!
( )insic February 12th
very nice! well explained.
( )Dean February 12th
Is it just me or can we not jump ahead in the video?
( )Jeff Hui February 12th
Nice tutorial!
I’ll have to agree that using an file to store your login information isn’t the best implementation for user auth. I wasn’t aware of PHP’s support for xml manipulation. thanks
( )Patternhead February 12th
Nice tut but I wonder how this would scale for systems with thousnads of users.
( )Tim Cooper February 12th
Thanks for the comments!
@Yoosuf, @Alessandro, @Jeff, @Patternhead: You’ve raised some valid questions. This solution would not be great for a large traffic site, as you said. The objective of the tutorial was to familiarize the users about the XML functions that are in PHP.
( )mokin February 12th
Very nice tutorial!
( )Matthijn February 12th
Didnt see the movie to be honest, but I would never use a xml file to store my users in. A database is made for things like that, much faster.
XML in my opinion is more on its place in RSS (so generated xml files, not static) and api’s.
( )noam February 12th
Thumbs up for the speed! i loved the tut!!
every time i watch a screencast i fast forward boring stuff… but in this one i didnt have to do it even once!! i think we should name those casts differently… like QUICKCAST
*thumbs up*
( )Bharat February 12th
Excellent tutorial!
( )Ryan Hickman February 12th
Iffy Post — SimpleXML doesnt work in all environments — If someone were using 1and1 they would be screwed.
I think this should have provided all 3 ways to access XML in php (simplexml, domDocument, xmlparser) and it would have been much more userful as a post.
I will give a thumbs up thou… its not bad.
( )Nat February 12th
Great Tut Tim. I agree with you: there are instances where apps based on flat xml data sources can be a simpler, more elegant solution than using a relational db – not necessarily for registration system – but cases do exist.
And I agree with noam: the speed was refreshingly quick.
( )Timothy February 12th
Nice. Thanks
( )Rik Girbes February 12th
thank you very much, i very much like it!!
im making a small cms system for my school (hehe xD im about the only one in my school that knows about programming stuff)
and this was perfect for a small group of users so thanks again!
*thumbs up* <<== everybothy says that so why should I?!..
bb
Rik
( )Jason February 12th
To address both sides of the field here.
No this is absolutely not a good solution for a site with anything more than a handful of users (or other data). However, XML is both smaller and faster, in certain situations, than the similar data transfer and query process of a database especially for situations where you will be accessing rarely changing data over and over again.
Right tools for the right job.
( )Ryan Stubbs February 12th
That was a really good tutorial. Might not be best for the login/registration but I’d never really understood how flat file systems were made until this. Thanks a lot!
( )rachid February 12th
Why creating an XML file for every user instead of putting them all in one file :
it will be very helpful if you want to check if the email does not already exist, or may be to get some user statistics !
login
exemple@exemple.com
1234
login
exemple@exemple.com
1234
nice tut !!
( )Brenelz February 12th
Yeah… excellent screencast! Wish I was as good at them as you.
On the other hand, I do think a seperate xml file for each is not very manageable. You could either put them all in one file:
Or even preferably use PHP/MySQL, but I know you wanted to show XML
( )Tim Cooper February 12th
Here is a modified version that uses a single XML file:
http://techietim.ca/files/xml_user_system_singlefile.zip
( )fugazi February 12th
thank you so much for this amazing tutorial
( )Valuediz February 12th
One of the most useful tutorial on Nettuts!
( )ericb February 12th
man this tut is awesome! good job! tim! ei, jeffrey more on xml tutorials please!
( )Merxhan February 12th
Great Tutorial, good explanation, very useful.
Thank you
( )monaye February 12th
Great tut!!
You didn’t mention anything about security, and wondering how secure is this?
just like the sql injection, is there xml injection??
I am sure there should be prevention for the session jack.
Anywhere great tut, and good for you that you’re still high school student. when i was high school…
( )Tim Cooper February 12th
@monaye: You can add more security if you desire. There’s only so much I can explain in 30 minutes
As for injection, I just realised I should have ran htmlentities on the user input. Without it, the user can insert their own XML nodes and cause problems.
So please, htmlentities user input!
( )Rashaud Teague February 12th
Hmm… you can also use SQLite if you don’t want to use a large platform like MySQL, Oracle, MS SQL, or PostgresSQL
That way you don’t have to stray to far from using SQL code…
http://sqlite.org
( )Jorge Bucaran February 12th
Love fast paced tutorials like this one.
( )Constantin TOVISI February 12th
Interesting idea to be using XML for storage of the login information, though I think I’ll stick to mySQL for the momment.
Nice tutorial anyways, and I’m looking forward to more of this screencasts.
( )yassir February 12th
xml -> IO problems , unsafe !! if someone knows the username he can get the password even with the md5 !
and you can’t do roles easly or profile …
i ll stick to ms sql ! even with small projects
( )dev February 12th
tht’s the second good thing to come out of nova scotia in recent times,
1. The lovely Ellen Page
2. Talented Tim Cooper
nice tutorial
( )yassir February 12th
@Tim Cooper — what if two users want to login at the same time ? or what if your file is getting large ?
( )Ben Blogged February 12th
Great Tut… thanks
( )David Singer February 12th
When will people stop using MD5. It was broken years ago. Might as well just use plain text if your going to use unsalted MD5’s.
p.s There is a label tag.
( )Pix February 12th
well this is a great introduction to xml function in php
but i think would be better check if an email already exists instead of checking the username
by the way nice job
( )Eneza February 12th
nicely done!!! Good Job
( )sx February 12th
better password method, stored different locations.
$user_salt=sha1(microtime());
( )$salt=”slfjlfljsdlfjsl;fjlsdfj;asdfj”;
$password=”passwordsample”;
md5($salt. $user_salt . $password);
Clemens February 12th
I’m not enirely sure about this, but shouldn’t you use === and !== to compare strings? Otherwise, you could cheat it with 0. If Strings are compared to Ints, they are converted to the first number, or 0 instead.
Test this:
”;
”;
( )< ?php
$string = “password or name or anything”;
$string2 = “password or name or anything”;
$int = 0;
if($string === $int) echo “I cheated
else echo “I failed to cheat
echo “”;
if($string === $string2) echo “Strings equal”;
else echo “Strings not equal”;
?>
Clemens February 12th
I want to add that this states that I failed to cheat, whereas a comparison with == instead of === would allow me to cheat.
( )Reader February 12th
Shouldn’t you verify the user’s password instead of username? If this was made into something with an admin area, all youd have to do is edit the cookie to say ‘admin’
( )rizq February 13th
Good Post !!!
( )Arnaud LEMERCIER February 13th
It’s a very good vidéo but two user with the same name was not possible
( )Andres F February 13th
Tim, that was very impressive. Thanks!
( )Jon Lisbon February 13th
PHP developers – stop making the world worse with your terrible language. Stop reinventing the wheel by making yet another user registration system. Stop catering to newbie developers who don’t know any better because they don’t have enough experience to know to stay well clear of PHP. Stop using MD5; it’s been shown to be cryptographically weak. Stop trying to be clever by not using a database.
I bet the average age of the readers here is about 20 and 98% of them use Windows, and have no formal training in computer science.
This is like some weird developer honeypot.
( )Tim Cooper February 13th
@Reader: The only cookie PHP sets is one to hold the session id. It alone does not hold any data that you can edit, such as the username being used.
How ever, I did not go into how to prevent session hijacking, which is a whole lesson altogether.
( )Marko February 13th
Bravooooo! MORE! MORE!
( )Yiannis February 14th
i have problem to watch your video
( )Jam February 15th
Though MySQL is obviously more secure, this would work well for a user system with data of little importance. That being said, this is quite a useful tutorial. Thanks.
( )Dan February 15th
Are you testing this locally on your machine? if so, what are you using?
when my test try to run the asXML function i see the following error:
“SimpleXMLElement::asXML(users/new.xml) [simplexmlelement.asxml]: failed to open stream: Permission denied”
Dan
( )Andrew February 15th
Could someone please tell me how to make line brakes after each user registration ?
Atm it writes all in one line xxxxxx
So after each new xxxx need a new line brake!
Thanks
( )Tim Cooper February 16th
@Dan:
You’ll have to chmod your users folder to something that will allow your web server access to it.
( )iDevelopThings February 16th
What a great video.. Keep them coming!
( )bestamius February 17th
What a nice article, thank’s very much!
( )Carlos L February 17th
@Tim Cooper:
How do you chmod [whatever]?
I had these errors:
Warning: SimpleXMLElement::asXML(users/juddcarlos.xml) [simplexmlelement.asxml]: failed to open stream: Permission denied in /Library/WebServer/Documents/register.php on line 28
Warning: Cannot modify header information – headers already sent by (output started at /Library/WebServer/Documents/register.php:28) in /Library/WebServer/Documents/register.php on line 29
Thanks! (And thanks to the OP!)
( )opnlnvrn February 18th
Your Message…
( )UGr February 19th
please visit my site for demo
( )http://www.yougroup.in/manish/site_3
Brian Barnett February 21st
I agree this wouldn’t be the best for users and passwords, but everyone please understand that in simpler terms this is a great jump for beginners into XML using PHP, someone could use this to sort their CD collection or movies. Besides, why get an entire mySQL db for something that can be done with a single file? Nice quick tutorial Tim, people should think of the other applications of this tutorial before bashing on it.
( )Justin February 22nd
Good job. Easy to follow and very organized source.
( )Thanks for the help.
Benji Barash February 23rd
Awesome tut Tim!
Interesting variant on the regular use of MySQL for login/register systems
Thanks!
( )Ramon February 26th
Gonna remake it to MySQL
( )ALEX18 March 21st
HI i’m alex.
( )First i want to say that ….man! y are fast and VERRY PRO.
Now i would like to ask something.
i add this mootools slide llogin tool in my website 2 screenshots, avablle.
Screen Shot1 – http://img14.imageshack.us/img14/1371/screengcm.jpg
–
ScreenShot 2 – http://img14.imageshack.us/img14/9411/18492524.jpg
__________________________________
Now how cann i make it work?….i saw this tutorial is realy good and its the first that i rally founded. but i would like to make this to work …..how?
PLEASE if someone whos a good codeing…designer…..,please help it’s my first template …and i;m using Dreamwaver cs4.
PLease take a moment from y;re live and help me.
i dont what tolet this unfinished cuz i payd alots of mony on Adobe Master.
TNX
My emails and Messanger.
jamaika_rnb@yahoo.com
18alx@live.com
—
THIS IS THE BEST designing and helping on the hole google zone that i found.
organicIT March 29th
Tim,
This TUT was outstanding. I am sure you meant for this to be only demonstration for XML interactivity and not for real world production use. Heck, you could have even mentioned it but we missed it you were so fast ; )
Anyway you have a long prosperous career ahead of you. Good Job
( )convertman March 30th
Your Message…
( )Zvonko March 31st
Great tut, but I would worry about security. Anybody could see your XML files and thus see username/passwords.
( )David June 1st
Hey, I had the same thought when he first did that, but, as u could see in the video he added a .htaccess file saying deny from all, and he showed it could not be seen. But I still think that it can be breached though. I’ll try to figure out a way, and try to get back on that.
( )Harman March 31st
How do u post it on a website?
( )kantslowdown April 7th
this is great…thank you!
( )DekuLink April 17th
Wow! Great tutorial. Lots of stuff to learn in this. Great for simple scripts like a news script where you only expect you or two people to use it.
( )Travis April 23rd
@Tim
Works on my local machine, when I login and test it on a live server I receive this fatal error:
“Fatal error: Cannot instantiate non-existent class: simplexmlelement in login.php on line 7″
Line 7 is :
“$xml = new SimpleXMLElement(’users/’ . $username . ‘.xml’, 0, true);”
Thanks!
( )Alex Mansfield May 8th
Interesting screencast. Thanks.
( )bhawani May 15th
i am getting problem while registration
Fatal error: Call to undefined method SimpleXMLElement::addChild() in E:\demoprojects\xml_user_system\register.php on line 26
( )ahmad May 31st
Hey ! your too fast man ! I love that !
Bookmarked this website ! will always come here
keep going people ! love that
( )David June 1st
Very Very Nice!!!
Very well explained, I understood so much in your video, and you speed is amazing.
( )e11world June 16th
Tim, you are the man. PHP is the way to go and this was a very nice, fast, “and detailed” tutorial. I think everyone who’s talking about security and other things should thank him for his time and effort into this instead of trying to make this sound incomplete. He obviously could’ve done this in many better ways (including using a database) but wanted to show everyone another solution.
( )Great Job Tim! Thank you
AnnaMarie July 14th
Your Message…
( )SophiaNirsam July 27th
Your Message…
( )John August 3rd
Firstly. let me say thanks.
I just used this for a client.
The client wants me to make it so that more fields (name, company name, telephone number) are added to the registration page and then he wants this info to be emailed to the client and to himself.
Could you please show me how I would do this?
Thanks again. Great website. Great tutorials.
( )Rob August 3rd
Ooohhhh very nice. I will definitely use this. Maybe not for user management but for user content like profiles, etc… Excellent, thank you.
( )