Redirect to a specific folder -PHP - 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

Related

use subdirectory as other purpose in laravel

I have installed laravel in my root of domain, its working fine. However
I want use one sub directory for other purpose like install admin panel in it. For example I have installed laravel in example.com Now I want install other core PHP admin panel in new sub directory called adminpanel. its like this example.com/adminpanel/
but when I try to access it, its giving me error called page does not redirect correctly. I have read somewhere that I can achieve it if I modify my .httaccess file but I have not much knowlede of it. Let me know if someone can help me for same.
Thanks!
Better option is creating an subdomain for the admin dashboard. Login into your cPanel and create a sub domain adminpanel.example.com set the path to your new folder.
Non cPanal
If you don't have cPanel, You should create vhosts for your subdomain in server config (apache/nginx).

Laravel, protecting a folder in public folder

I have a folder inside the public folder in Laravel app, this folder is called 'docs' and I want to protect it from unauthorised access. So basically when a user tries to access this folder they should get redirected to the login page. I tried doing this:
Route::get('\docs','DocsController#protected')->middleware('auth');
But Laravel doesn't even get triggered and the user goes directly to the folder.
You can use .htaccess file to protect this folder. But IMHO the better way is to move this folder from public, and access the docs using php code (using something like thephpleague/flysystem).

Codeigniter redirect main folders (application, system)

I build an application with codeigniter and I wondered if it was possible to redirect access to major folders such as application, system.
Currently, I get the message "Directory access is forbidden." but can we not go redirect to one same controller ? it is not possible to have a controller named "application"?
I use Nginx 1.4.4. Thank you.
Ok you can do it by creating an index.php file in your folder an putting a redirection :
<?php
/**
* Redirect to application index controller
*/
header('Location: ../application/index');
It worked for me.

persistence in certain directory

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

how to hide url in cakephp?

I m doing web application in cakephp1.3. I want my Url
http://mydomine.com/cakephp/users/login to be display as http://mydomine.com/users/login.
Where users is controller name and login is action. I dont want to display cakephp on my url. Please help me to fix this bug.
Thanks in advance
Pushpa
You can direct your domain to the cakephp directory... No need to work with rewrite.
either move all the files from the cakephp folder to the / folder,
or use apache rewrite rules to remove cakephp from the request
Put all of the content of your app dir to your web folder and then u will be able to access home page of your project directly. Don't forget to copy .htaccess.

Categories