如何获取包含php文件的页面

I am working on a simple book store project. I have made a login page. The login page has the following line: require("includes/dbCommon.php"); This is done so that I can connect to the database to get the users info(their salt and their hash to make sure they put in the correct password) to make sure they logged in correctly. I know that in the real world, error handling is a must because when something breaks and a user does not know how or why it happened. They go a report the problem. When a user submits the login data it goes to the login script which then processes the data. The login script first and foremost connects to the database which has a chance to fail(the database may be offline or something random happened). Lets say the user has entered wrong login details. The login script then redirects back to the login page with data in the session to show the the login page that the user provided incorrect details. The login page then shows the error to the user. Now, lets say the login page attempts to connect to the common code for the database but the connection fails. Note the register script connects to the same code so how would I make it so that the database redirects to the correct page that called it. So if login.php called it, then how would I tell it to redirect to login.php? Also if register.php called it, then how would i tell it to redirect to register.php?

You can use PHP $_SERVER variable. It's a useful array containing a lot of information. The specific key you need is HTTP_REFERER.

Use it in a line of code like this:

$referer = $_SERVER['HTTP_REFERER'];

PHP help on the subject is here.