Jump to content

PHP Tut on W3Schools


knystrom18

Recommended Posts

If a login was required to access a site, could the logins of all the users be stored in a php file within a variable/variables?I know there are probably a million different and better ways to do this with MySQL or something, but this is just a question to see if I'm getting the whole "gist" of PHP so far.

Link to comment
Share on other sites

Just to be sure here...index.php has an submit button that when clicked posts the entered login data to a script (login.php). login.php looks at members.php which has the usernames and passwords of each member in a readable format for the php engine. (comma delimited?)login.php finds the corresponding values for what was entered into index.php within members.php and through an "else...if" statement, directs the browser to a successful login page, or back to index.php if the values don't match. :)

Link to comment
Share on other sites

If you are literally updating the document, using fwrite() or file_put_contents(), then yes. It does not have to be a .php document or look like PHP code, and probably it would be easier to manage if it did not. The normal strategy is fields and records delimited by commas (or tabs) and newlines.If you are hoping that your php document can be executed at different times and somehow its variables will store the data created during precious executions, then no. Every time a script executes, it creates a new set of objects. The old ones are gone.

Link to comment
Share on other sites

You could have a .php file with an array of all the users indexed on username and use include() or require() to pull that array into your pages for use.I don't know if that's very secure but it is an option.
Aight, cool. Thanks.
Link to comment
Share on other sites

If you are literally updating the document, using fwrite() or file_put_contents(), then yes. It does not have to be a .php document or look like PHP code, and probably it would be easier to manage if it did not. The normal strategy is fields and records delimited by commas (or tabs) and newlines.If you are hoping that your php document can be executed at different times and somehow its variables will store the data created during precious executions, then no. Every time a script executes, it creates a new set of objects. The old ones are gone.
I wouldn't be updating anything. Unless the status given to a user as being logged in is considered an update, but nothing would change in any php files would it?I don't think that anything would need to be "remembered" either, as a login is a one time process per user every time they login, unless they choose to "stay logged in."You know waaaay more than me though in php so I'm prolly just talking nonsense. :)
Link to comment
Share on other sites

A user logging in is not going to change anything as far as stored credentials. If you want them to be logged in until they close the browser you'll need to use sessions. Otherwise everytime they navigate away from your page they'll have to log in again when they come back. That includes other pages in your site too. In fact, the more I think about it the more I think you aren't going to be able to do it without using a session.Here's the link, if you need more help just ask. I can't help you since I don't know how to create them either, but others here can.http://w3schools.com/php/php_sessions.asp

Link to comment
Share on other sites

If you want to store large data structures in a file, check into serializing:http://www.php.net/manual/en/language.oop5.serialization.php
I do not want to detract from the original authors intent, but just wanted to say thanks for introducing me to the section on Classes and Objects, it provides much better explanations about how PHP works than do the brief definitions provided for individual functions.Roddy
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...