Solved

select destination folders based on login

Posted on 2011-03-24
7
221 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
Comment Utility
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
Comment Utility
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
Comment Utility
@ 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 5

Expert Comment

by:tsmgeek
Comment Utility
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
Comment Utility
$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
Comment Utility
@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
Comment Utility
After a lot of trying i got it working, with the directions you gave me!

thanks!
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

744 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

17 Experts available now in Live!

Get 1:1 Help Now