Solved

select destination folders based on login

Posted on 2011-03-24
7
225 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will learn how to dynamically set the form action using jQuery.
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…

730 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