I have my WordPress site at xroads.com
Inside, there is a folder called “_warehouse” which contains a php CRUD app
Is it possible to require the same login page I use for the WordPress site to view the _warehouse directory?
Thanks in advance!
I have my WordPress site at xroads.com
Inside, there is a folder called “_warehouse” which contains a php CRUD app
Is it possible to require the same login page I use for the WordPress site to view the _warehouse directory?
Thanks in advance!
Comments are closed.
If the user already has an account in WordPress:
Redirect the user to the login form. Use
wp_login_url
with the$redirect
parameter to set where they go after logging in:https://codex.wordpress.org/Function_Reference/wp_login_url
Then use the
wp_login
action to manually authenticate the user in your application:https://codex.wordpress.org/Plugin_API/Action_Reference/wp_login
Actually setting the user as “logged in” is going to depend on how your external application is setup. It could be as simple as setting a session variable and then checking if that is set in your warehouse app.
Here is one possible solution (use at your own risk).
Create a
.htaccess
file in the_warehouse
directory with the following content:This will redirect all requests for files that exist in
_warehouse
and any subdirectories to_warehouse/wplogin.php
Create
_warehouse/wplogin.php
with the following content:Lastly, and very important, add this to your
wp-config.php
file:This is because WordPress will set cookies with a path specified. This would prevent the login cookies from being recognized in
_warehouse
.And as I said, use at your own risk. It is not perfect but is probably the quickest way to achieve what you want and will handle many cases.
Note: it doesn’t deal with directories with no index. If Apache
Options +Indexes
is on, someone may be able to see directory listings in_warehouse
but if they try to access one it will show the login page.