Reputation: 49
I have a simple user files like this
joe.php
<?php
$pass = 'joepassword';
$userpath = 'work/joe';
?>
sam.php
<?php
$pass = 'sampassword';
$userpath = 'work/sam';
?>
I use these files for text authentication one is included once the user logs in setting the path for that user while checking the authentication. Once authenticated, I immediately overwite that $pass variable with"text" so the password is not available as a variable to prying eyes.
Now I need to log in as "joe"
so I include joe.php sessing $userpath
$userpath='work/joe'
I now need for admin purposes, to access sam's $userpath as a destination, and joe's $userpath as a source at the same time but if I include sam.php I will be overwithing joe's $userpath
I figure there is a simpler solution like using fopen and extracting only the (second) path for sam, but not sure how to go about this.
I am not posting this for a lecture in security so please abstain from responding about secirity. These files are not in a folder accessible to the web server anyway.
Upvotes: 0
Views: 435
Reputation: 49
Despite most people barfing up the wrong tree which do not answer the question, the answer is amazingly simple. Set session variables from the originally included file and use the session variables from then on. The second call to that or similar file set a second set of session variables.
after including joe.php in auth.php
$_SESSION['userpath']=$userpath;
Then , even on the same page or other pages we can include
joe.php
<?php
$pass = 'joepassword';
$userpath = 'work/joe';
?>
now when we include sam.php (the second one)
$_SESSION['touserpath']=$userpath;
Upvotes: 0
Reputation: 1702
Make them classes:
class Sam() {
public $userPath;
public $password;
public __construct($path,$password) {
$this->userpath = $path;
$this->password = $password;
}
}
class Joe() {
public $userPath;
public $password;
public __construct($path,$password) {
$this->userpath = $path;
$this->password = $password;
}
}
$joe = new Joe("user path here", "my password");
$sam = new Sam("another user path", "another password");
echo $joe->userPath;
echo $sam->userPath;
echo $joe->password;
echo $sam->password;
Upvotes: 1