The script structure of the backend of the site is VERY simple. I will not write the code which does db stuff, only the code related to my prob. All request scripts are composed the following way: all the processing code is written there and after all the required data is collected, a template (PHP + HTML) is included which itself includes appropriate content (also HTML + PHP) file. The template and content files are stored in /pages dir. The variable I am having problems with is $_SESSION['msg'] (it is used to store any message I need to print for the user). Each content page has this snippet embedded to echo $_SESSION['msg'] and then 'erase it':
Code: Select all
echo $_SESSION['msg'];
$_SESSION['msg'] = '';Code: Select all
//Not yet logged in
session_start();
$_SESSION['msg'] = '';
include('pages/index.php'); //display template to user, since not logged in, echo $_SESSION['msg'] prints no messages
//exit
/* ... */
//If login is submitted and correct
//set some other session vars
header('location: home.php'); //redirect to home page of the backendCode: Select all
session_start();
//Check if logged in
//Some language switch code
include('pages/index.php');Code: Select all
session_start();
//Check if logged in
include('pages/template.php'); //template.php has include('pages/add_news.php'), that is, it includes content page (form in this case).Code: Select all
//HTML code
<?php
echo $_SESSION['msg'];
$_SESSION['msg'] = '';
?>
//HTML form
//HTML codeWhen I need to print some messages via echo $_SESSION['msg']; the messages sometimes have 'U' in front of them (it replaces the first letter), although in my files they are written ok. This doesn't happen with ALL messages, but with some it certainly does. In one case I only have 'U' instead of the whole message. I have all messages stored in a single file:
Code: Select all
//class.Database.php
$msg['NoDB'] = 'Unable to connect to database.';
//class.Authorization.php
$msg['InvalidLogin'] = 'Invalid username or password.';
//class.Validator.php
$msg['EmptyField'] = '<b>{field}</b> field is empty.';
$msg['InvalidField'] = '<b>{field}</b> field is invalid.';
//General
$msg['NewsInserted'] = 'New item inserted successfully.';
$msg['NewsUpdated'] = 'Item updated successfully.';
$msg['NewsDeleted'] = 'Item deleted successfully.';
$msg['MassNewsDeleted'] = 'Selected items deleted successfully.';
$msg['NewsNotFound'] = 'Requested news item does not exist.';
/* ... */Code: Select all
$_SESSION['msg'] = $msg[$object->getError()];I hope someone might spot what could be causing the problem.