Solved

select destination folders based on login

Posted on 2011-03-24
7
222 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

895 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now