select destination folders based on login

Posted on 2011-03-24
Last Modified: 2012-05-11

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?

Question by:peps03
  • 4
  • 2
LVL 27

Accepted Solution

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/';

Expert Comment

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


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


Author Comment

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?

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.


Expert Comment

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');

Author Comment

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');

Author Comment

ID: 35214385

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');

Author Closing Comment

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


Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

786 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