Our development team just moved an app from a local server up to a live site. The app utilizes remote databases that can be written to and utilize MSQLi as well as PDO methods to get and push data to the database.
After updating the connect .inc files to have the proper database credentials the web app works on the back end. Data is getting to the database by way of the forms. However, session variables are not being set for some reason. Now, I am left with the nefarious and almost traditional web dev question:
"why does it work on the local server but not on the live site?"
I did a quick session test where a dummy session variable is set and echoed and it rings like a bell. The issue comes with setting sessions post query. That is to say after the query is run, the data passed is sanitized once more and passed to a session variable. A good example of this follows.
if ($query_dummy = $query_putitthere)
{
$_SESSION ['name'] = $name;
$_SESSION ['date of application'] = $date;
$_SESSION ['certifications'] = $certs;
$_SESSION ['address'] = $addr;
header ('Location: next_page.php');
}
Like a good little PHP developer, OB_start
and session_start
are both located at the top of the PHP docs and again they worked on the local server with the same code. The only thing I could think to be the issue would be when we changed the credentials for the new DB that something happened but that does not make too much sense since the data is making it to the DB just fine.
I doubt this is a PHP configuration issue because you'd think sessions and PHP's behavior in handling would have to be consistent no matter what version is running. Stranger things have happened however.
The variables are sanitized on the front end by way of msqli_real_escape _string
. An example is as follows.
$name = mysqli_real_escape_string($connect, $_POST['your_name']);
$date = mysqli_real_escape_string($connect, $_POST['date_of_app']);
$certs = mysqli_real_escape_string($connect, $_POST['certifs']);
I realize I may have misspoken when I said they were sanitized one more time before getting to the session. In reality when the sessions are passed, they get sanitized on the second page by way of html_enttites
.
The mentality being that MSQLi takes care of sanitation from user input and html_entities takes care of any flukes that may have slipped through the cracks on the back end.