简体   繁体   中英

How can I access sql login info outside of web root

I'm a newbie.

I have a php script located here /var/www/check_login.php that includes sql login information in plain text. This file is accessed to verify correct user credentials by my login page /var/www/login.php via <form name="" method="post" action="check_login.php">

I'd like to store check_login.php outside of web root directory so it cannot be accessed remotely.

How would I tell login.php to access check_login.php outside of the web root directory?

I'm guessing its not as simple as action="/var/<new folder outside of root>/check_login.php

Thanks!!

将带有凭据的文件移动到一个上一级目录和文件check_login.php中

include('../credentials.php');

You're on the right track. Create a different folder for your site in /var/www. I like to do this setup:

/var
---/www
-------/mysite
----------/html
----------/config
----------/lib

etc. In apache, I tell it my document home is

/var/www/mysite/html

and then I store any config files (like MySQL credentials or classes) in /var/www/mysite/config . Then, I can include these files with something like:

require_once("/var/www/mysite/config/mydbcreds.php")

In your example, login.php would need to call your check function in this file, and would be able to if you require it to be included. Check out my answer here on how to use a MySQL connection class that may save you some time and headaches.

Create a new page for your database connection information and move that to /var/

You can then use your HTML action="check_login.php"

and on your check_login.php script, use the solution which Gustek suggested:

include('../credentials.php');

你可以简单地使用include('path of folders/ your_ logging_data .php );

If you're on a shared hosting plan, I would simply create a new folder outside my website root and have all my non-public files in there. Then in the php.ini file for your website, I would edit the include path to include this new folder. In your .php file, simple put require("the-non-public-file.php"); at the top, ie, without the absolute path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM