简体   繁体   中英

PHP\MySql Multiuser System Backend Structure

I'm writing a multiple user log in system using PHP and MySql, the way i have done it in the past is to have a central "processing" file that will handle all of the code on the backend, like logging in, messaging other users etc..., I've used forms with hidden fields to define which action to perform in the processing file.

heres a quick example.

the login form:
<form method="post" action="process.php">
Username:<input type="text" name="username" /><br />
Password:<input type="password" name="password" /><br />
<input type="hidden" name="action" value="login" />
<input type="submit" value="Login" />
</form>

the processing file:

<?
$action = strtolower($_REQUEST['action']);
switch ($action) {
case "login":
* get the username and password from the form
* query against the SQL database
* set appropriate session data if login was ok
* redirect to homepage for logged in users with a header("Location: home.php");
}
?>

is this the best way to handle this? or should i say be using classes and separate files, including these into the login form. and then post back to the login form and check the data there?

Thanks for reading, cyrix

I would say move to OOP and look into using a framework to handle your application routing and functionally separate your user-interface, business logic and data layer (MVC). This will effectively make your code much more modular and reusable. Relying on a hidden field to determine the action probably isn't the most reliable or effective method for determining what way your application should behave.

Some frameworks I would recommend:

Zend Framework - Has nearly everything you could possibly imagine, but slow.

EuropaPHP - Extremely fast, lightweight and easy to use, but no extra libraries. Works with the Zend Framework.

CodeIgniter - Fast, lightweight and extensible with good documentation.

Prado - Very mature component based framework. Not very fast, but solid.

A big list of MVC frameworks for PHP can be found at: http://en.wikipedia.org/wiki/Model–view–controller#PHP .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM