Here's my problem: I have one file that contains a local function (VRC_Header.php). Here it is:
function sec_session_start() { $session_name = 'sec_session_id'; //set a custom session name $secure = false; //set to true if using https $httponly = true; //This stops javascript being able to access the session id ini_set('session.use_only_cookies', 1); // Forces sessions to only use cookies $cookieParams = session_get_cookie_params(); //Gets currtent cookies params session_set_cookie_params($cookieParams["lifetime"], $cookieParams["domain"], $secure, $httponly); session_name($session_name); //Sets the session name to the one set above session_start(); //Start the php session session_regenerate_id(); //regernates the session, delete the old one } It's simple enough. I include this file in every public page. For instance,
include_once('VRC_Header.php'); include_once('../Classes/VRC_MasterOO.php'); include_once('../Classes/VRC_Secure_Login.php'); //Start a secure session sec_session_start(); My problem is occurring between my login page to a php processing page. The submission occurs via a post jQuery function. This second page contains code identical to the above:
include_once('VRC_Header.php'); include_once('../Classes/VRC_MasterOO.php'); include_once('../Classes/VRC_Secure_Login.php'); //Start a secure session sec_session_start(); Unfortunately, my jQuery function replies with this:
Fatal error: Cannot redeclare sec_session_start() (previously declared in E:\Additional Programs\xampp\htdocs\Vista_Ridge_Territory_System\PHP\Scripts\VRC_Header.php:14) in E:\Additional Programs\xampp\htdocs\Vista_Ridge_Territory_System\PHP\Scripts\VRC_Header.php on line 24
Note that my jQuery function presents the reply - meaning that I believe the problem resides in the second file. Hence, the "cannot redeclare." Why is this happening? I've not had this issue before with local functions.
Any input is appreciated.
Note: I have removed the include function in both files. If I do, PHP throws another error: "sec_session_start()" is not defined."
The intermediate jQuery function:
$(document).ready(function () { $('.login-form').submit(function (e) { e.preventDefault(); $('#reply').remove(); var formData = $(this).serialize(); $("input").prop("disabled", true); request = $.post('VRC_LoginProcess.php', formData, loginMessage); request.fail(function() { $('.header').append("<span id=\"reply\">Login Failed. Please try again in a few minutes.</ span>"); }); function loginMessage(data) { $('.header').append("<span id=\"reply\">" + data + "</ span>"); $("input").prop("disabled", false); } }); });
include_onceand notinclude?$session_name = 'sec_session_id';. Directly before that is the start of the function. Line 24 issession_regenerate_id();. That is right before the end of the function.