Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Konrad Pilch
Konrad Pilch
2,435 Points

PHP User log in , lots of users

HI,

Could somebody give me an idea of how can I make a user with OOP in PHP? I mean that the if th euser 1 logs in, he will have his information and if the user 2 logs in, he will have his information. And it will show on their name.

3 Answers

I agree - working through it yourself first is a great way to learn!

There's quite a nice fix for creating a profile that doesn't require much logic. When a user 'logs in', I imagine you're submitting something that identifies them to the session. This might be their ID from the database. It might be an encoded string. As well as their ID you could submit more details to save database queries, but I'll leave that to you.

Now you have the userID, you can grab their information wherever you need. I have to say that I'm not a web security expert and have no idea if this is a secure way of handling authentication / logging in and out. It will get you started on your example, but as with everything, more learning required!

Konrad Pilch
Konrad Pilch
2,435 Points

HI,

Thank you for response :)

And i agree with you : p i need way more learning : p im following this and well, i just started and did research and i know that theres way more work than i though it will be. I mean, i believe its somewhat easy, but it just another way , with the OOP and the templates which i havent learned well.

I hope i can get throw this tutorials, it been 3 years when created but i see some commments from 1month that says thats ok.

I tried to do some functions , but all crashed : d deffenitely i need more learning onto mving to it : p

I took quite a lot of tips fomr him too, last night he said about the frameworks too :)

Konrad Pilch
Konrad Pilch
2,435 Points

But this seem and it is soooo cool! I cant wait till i launch my simple project online :D though, the most worring part is security . I mean, i will go over blogs and blogs days before i launch my little or medium project but really, i have no idea what so ever about ahcking and stuff : p Treehouse should deffenitley do a course on security, i think its in the requests :)

Yeah that would be cool! The trouble is, security is incredibly fast paced! I wonder how long the material would be valid for :p But cool! Look forward to seeing it :)

Konrad Pilch
Konrad Pilch
2,435 Points

Thats the thing im the most scared of : p but i hope i will be able to mantain the site :) without any trouble, though what im doing, the two projects, will have quite a lot of people, or at least, with time . I believe the best thing is to ask a a team treehouse teacher maybe : p

Konrad Pilch
Konrad Pilch
2,435 Points

Do hackers/crackers do actually do this stuff? i mean , if i have my own business, of course coded my me , and im pretty new, but lets say i get 10k hit ( from my followers im assuming or facebook ) and the site get kinda popular , well you know what i mean, will hackers/crackers actually try to mess up with my site? what about the law? wont they like get locked ? : p i mean f their doing something illegal, the police-hackers should do something or even the host its self maybe? or how does this even work?

Haha, there's some famous quote which is something like "no matter how small you are, someone will always try". To be honest, I would worry about it too much. There are some basics like escaping out, stopping sql injection and making sure your database credentials are unavailable to the outside world etc.. Beyond that your looking at things like https and other encryption-ee things.

Konrad Pilch
Konrad Pilch
2,435 Points

Hmmm, i saw a lot of tutoruals about injection plus there are few at treehouse somewhere from Randy too . I believe i will have good look in google and search for articles, blogs , vidoes : p but as soon as i get a basic security , it should be fine right? and of course, the more i learn, i will upgrade it. When is tarted with HTML and CSS last year, i would laugh how i did thing : p and i believe it will be the same in 6-12 months : p

Well, believe me or not, im quite, small but strong :D While big guys like Apple and Microsoft get down, i stay on my feet :D xD

Adrian Randall
Adrian Randall
4,807 Points

That's a pretty open question

Are you using a framework (Zend, Yii) or even a CMS (Wordpress, Magento, Drupal, Joomla etc) or just doing it from scratch?

Theres a lot to do before you can have an authentication based structure to your app...

Konrad Pilch
Konrad Pilch
2,435 Points

I dont use frameworks when i first learn. Its better to learn it the hard way first .

I did the registtration form , but now i want to do it in the way of making the user object . I dont care aout security, im doing it for learning purposes .

Adrian Randall
Adrian Randall
4,807 Points

I'd use a framework, no point re-inventing the wheel...

However if you want to do it this way I guess you could create a database with a model containing user fields and then authenticate against this and store "if logged in" in a cookie...

Konrad Pilch
Konrad Pilch
2,435 Points

Yes but when learning, it's better to write it alone first as you learn more, instead of learning framework straight away. That's my opinion, framework I'd good after I achieved a good standard in PHP, like with bootstrap nd css.

What i mean, how do I make a user? Let's say I hv 20years in my database, how do I make them log in so they have their own info when logged in not somebody else? Do I use like the private? Nd set name lastname etc..?