Solved

select destination folders based on login

Posted on 2011-03-24
7
226 Views
Last Modified: 2012-05-11
Hi,

I use a simple 1 page cms-system for simple sites. what i want to do is "load" different destination folders based on the username that is used to login. (no databases used)
> i can add the username / password combinations in the settings file, along with the correct folders

so the username and the folder-settings are in the settings file that is included:
define ("USERN", "admin"); //Site username
define ("PASSW", 'test'); //Site password
$IMAGEDIR = 'uploaded/admin/images/';  // for images
and so on.

so if username "admin2" is used to log in it should look like this:
define ("USERN", "admin2"); //Site username
define ("PASSW", 'test2'); //Site password
$IMAGEDIR = 'uploaded/admin2/images/';  // for admin2's images

how can i do this?

Thanks!
0
Comment
Question by:peps03
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 35209714
If your user logs in with let's say $username = "admin1"

define ("USERN", $username); //Site username
define ("PASSW", 'test2'); //Site password
$IMAGEDIR = 'uploaded/$username/images/';
0
 
LVL 5

Expert Comment

by:tsmgeek
ID: 35210013
personaly i would santitise the username before you use it, best would be to authenticate with the user first in the db then use the DB username in the directory path if auth passed, that way what the user enters onthe front end is never directly entered into file paths etc

ie.

$username="abc1";
mysql_query(sprintf("SELECT * FROM users WHERE username ='%s';",mysql_real_escape_string($username)));
$row = mysql_fetch_array( $result );

define ("USERN", $row['username']); //Site username
define ("PASSW",$row['password']); //Site password
$IMAGEDIR = 'uploaded/'.$row['username'].'/images/';

Open in new window

0
 

Author Comment

by:peps03
ID: 35212059
@ Roads_Roads,

Thanks very much for your reply. Could react earlier, sorry.

It almost works as i want it to, except for this line:

$ALLOWEDFILES = array ('html/'.$username.'/*.html', 'html/'.$username.'/*.php');

what am i doing wrong here?

thanks!
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 5

Expert Comment

by:tsmgeek
ID: 35212122
dont know exactly what you are trying to do with that line but i would write that as....


$ALLOWEDFILES = array ('html/'.$row['username'].'/*.html', 'html/'.$row['username'].'/*.php');
0
 

Author Comment

by:peps03
ID: 35212152
$username indicates a folder, but is isn't working like this:

should this work?

$ALLOWEDFILES = array ('html/'.$username.'/*.html', 'html/'.$username.'/*.php');

supposed to output:
$ALLOWEDFILES = array ('html/folder/*.html', 'html/folder/*.php');
0
 

Author Comment

by:peps03
ID: 35214385
@Roads_Roads,

it works so far..
but, how will i now make multiple users?

$username = "john"; // user1
$username = "mark"; // user2
define ("USERN", $username);
//Site password
define ("PASSW", 'test');
0
 

Author Closing Comment

by:peps03
ID: 35265185
After a lot of trying i got it working, with the directions you gave me!

thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question