persistence in certain directory - php

I am making a web app in which there are four directories user, admin, superadmin. I am login user and directing each of them to these directories using sessions depending who the user is and it's working out well.
How can I ensure that the user session persists in the directory they are in until they log out. For instance, if I log in as admin, I would like all my sessions only to persist in the admin directory without going to another directory. I do not have and idea please help
This is path to the root folder: F:\wamp\www\authentication\public\
admin : F:\wamp\www\authentication\public\admin\
user : F:\wamp\www\authentication\public\user
I do not want to return to the root directory which contains this directories.. Kindly assist me and give me sample codes.

$conflen=strlen('SCRIPT');
$B=substr(__FILE__,0,strrpos(__FILE__,'/'));
$A=substr($_SERVER['DOCUMENT_ROOT'], strrpos($_SERVER['DOCUMENT_ROOT'],$_SERVER['PHP_SELF']));
$C=substr($B,strlen($A));
$posconf=strlen($C)-$conflen-1;
$D=substr($C,1,$posconf);
$host='http://'.$_SERVER['SERVER_NAME'].$D;
$path=$host.dirname($_SERVER['PHP_SELF']);
define('FRAMEWORK_PATH', $path.'/');
This is working but give more answers. i found it in php manual

Related

Redirect to a specific folder -PHP

So I created a register/login system. Once they register, a folder will be created automatically with their username as the folder name(like a personal folder). I want them to be redirected to that folder once they logged in.
Can I use:
header("Location: http://example.com/Parentfolder/theusersfolder);
then replace theuserfolder to redirect the user to his folder? or something that might help?
Instead of creating Folder. You can use dynamic Routing. It will also help you when user renames their username.
If you are using Core PHP these links will help you
How to route Dynamic url in Core php
https://medium.com/the-andela-way/how-to-build-a-basic-server-side-routing-system-in-php-e52e613cf241
Or you can use any PHP framework

Nested file's URL in PHP

I am working on admin panel to add/edit/delete the posts.
So far I had all php files in root directory but I would like to structure it and put admin's related files in other directory(root/adminFiles) and here comes the issue of accessing adminLogin's URL as I was accessing it by typing domain/adminLogin and after moving admin's related file to different directory I would have to type domain/adminFiles/adminLogin.
I was thinking about renaming adminLogin.php to index.php (I think this is how Wordpress solved it) but then I have more than one index.php and it may be confusing, please advice best solution

best way to give permission to admin website user to modify public site?

I have a website, let's call it "public" with an admin site, let's call it "admin."
Both websites are hosted on the same Debian server and each site is owned by a different user: public_user and admin_user
public site is in var/www/public
admin is in var/www/admin
Now; using php mkdir() and copy() from the admin site I would like:
1) Create a folder inside the public site.
2) move/copy files within public from the admin site.
From admin I would like to do the following inside public:
Create a folder in www/public/assets/images
Move images from www/public/assets/temp to my newly created folder
At the moment I have "permission denied"; I could chmod 777 but surely there must be a safer and better way?
What would the pros do?
If you have the ability to setup user groups on the server,
Setup a new user group
Assign both public_user and admin_user to the group
Then assign the desired folder(s) [www/public/assets/images] to the group with read/write (and if necessary, execute) permissions.
After that, you should be able to copy files/move files to said folder as either user.
For more info, refer to the Debian administration documentation for adding groups and adding users to those groups.

.htaccess inherit "require user" in subfolders and add specific user

I have multiple interfaces to manage different sections of our website.
Every user is responsible of his own section, and should just have access to the interface of his section.
some users like Webmaster, Big Boss and website content manager (let call them VIP) must have global access to all the interfaces.
To manage access to each section, I use a .htaccess file in the root folder of each section, with specific users for each one. But in order to geive access to all sections to VIP, I have to write theire names in all the .htaccess files.. this causes me a lot of work when one of them changes or if I have to create a new global access to some new manager.
is there any way for me to put the global access informations in one .htaccess file in the root folder (which contains all the sections as sub folders) and inherit this in the subfolders while adding specific users for each subfolder?
I hope I was clear.. thank you in advance
You will probably want to implement HTTP Basic Authentication (that's what you are doing with the .htaccess file right now) in PHP.
There is a tutorial on HTTP Basic Authentication on the PHP website.

Need use PHP to read directory directly not layer by layer

I need to access a remote URL like \\filesystem\XXX\YYY.
And the remote URL manager allows me to access \\filesystem and \\filesystem\XXX\YYY, while \\filesystem\XXX does not.
so opendir("\\filesystem") works fine, and opendir("\\filesystem\XXX\YYY") return false.
I guess opendir() read its path layer by layer, so it returns false when it goes to \\filesystem\XXX.
Is there any way to access the URL directly?
Here is my situation.
I'm in Department A and there is another department called XXX. They put their documents in \\filesystem\XXX and make a directory YYY to share some files with other departments.
That's why I have permission to access \\filesystem and \\filesystem\XXX\YYY ,but not \\filesystem\XXX.
Thanks for helping me to solve this problem. I called system("whoami") to find out that apache is running by a system account without permission to access \\filesystem\XXX\YYY.

Categories