Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Web Development
You last visited: Today at 08:20

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[PHP]Multiple sessions handle

Discussion on [PHP]Multiple sessions handle within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 167
Question [PHP]Multiple sessions handle

Hi guys i'm learning basics of php, didn't read anything just start programming

I want to try developing an app that will have 3 posible session rights:

->Root : Complete access (read/write) to databases. (add/remove admins,drop tables,etc)
->Admin: Limited access to some tables (add/remove Downloadable content,etc)
->Guest: Read downloadable content table and download files...

This is the code by now:

index.php

login.php

admin.php|root.php|guest.php

Now my question is, how can i make it better?, i don't know if this way is good for what i need or if what i did is all wrong

P.S: I'm ussing xampp

Thx for your time
elmarcia is offline  
Old 04/14/2016, 10:02   #2
 
elite*gold: 100
Join Date: Apr 2008
Posts: 860
Received Thanks: 1,488
Thats pretty good for now. Keep working and your techniques will "evolve".

Some points to start:

1. You may want to avoid duplicate code like:
Code:
if(!isset($_SESSION["user_type"]) or $_SESSION["user_type"] != "root")
{
header("Location:/miapp/"); //Go back we aren't root or not session set yet.
}
Put it in a function called e.g. require_privilege("root");

Try to avoid duplicate code at all. When you notice you're reusing code from other files, consider defining it as a function. Not everything is a suitable function, but get used to functions.


2. After setting header('Location: ...') you should exit the script.
Otherwise the code after that may still be executed (without you having the corresponding permissions):
Code:
if(!isset($_SESSION["user_type"]) or $_SESSION["user_type"] != "root")
{
header("Location:/miapp/"); //Go back we aren't root or not session set yet.
exit; 
}
3. Database Security
Code:
$query = "SELECT * FROM usuarios,tipo_usu WHERE usuarios.id_tipo = tipo_usu.id_tipo AND usuarios.user='".$user."' AND usuarios.password='".$psw."'";
SQL-Injections will occur. Avoid building your query like this. Use Prepared-Statementes. Easy, secure.
(< thanks emote -.-)

4. Templating
Think about separating your code and your html into different files. PHP is, by design, just a big template system. Your code is simple for now, but when it gets more complex, give that a try.
It's easier to work on the code without having html-tags floating all around and it's easier to work on the design without complex php-code everywhere.
florian0 is offline  
Thanks
1 User
Old 04/14/2016, 15:35   #3
 
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 167
Thx u so much i will read and continue improving
elmarcia is offline  
Reply


Similar Threads Similar Threads
Biete 12er HB Sessions + 2er DB Sessions Suche 4er DB Sessions + D3 KEYS oder Accs
02/28/2013 - World of Warcraft Trading - 2 Replies
So wie ihr im Titel lesen könnt suche ich das und nix anderes. Mfg.: Denny456 Auf wunsch gebe ich auch gerne Screenshots raus und werde einen MM suchen für den trade.
Biete 12er HB Sessions + 2er DB Sessions Suche 4er DB Sessions + D3 KEYS oder Accs
02/23/2013 - Diablo 3 Trading - 0 Replies
So wie ihr im Titel lesen könnt suche ich das und nix anderes. Mfg.: Denny456 Auf wunsch gebe ich auch gerne Screenshots raus und werde einen MM suchen für den trade.
[Verkaufe] Demonbuddy Lifetime key - 6 Sessions (verdoppelt von 3 Sessions)
08/10/2012 - Diablo 3 Trading - 0 Replies
Akzeptiere nur Überweisung als Zahlungsmethode. Ihr überweist zuerst das Geld (ihr habt zur Sicherheit meinen Namen für die Überweisung...). Ernsthafte gebote bitte via pm. Ps. Ich behalte mir vor meine Tradepartner auszuwählen



All times are GMT +2. The time now is 08:20.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.