Nothing wrong with the code it works fine but on some templates not.
Here is how it works:
I store an array of templates into session and shuffle them only if the session is empty. Each time the page is reloaded, i pop an element of the session. So each time a template is included in the page, it pops out from the array
The issue here, on some templates the array_pop
function pops 2 elements of the array on page reload (the included template + an other one).
I have tried to delete some code on the "problematic" templates but i cannot find a solution.
I need some help how to identify this issue.
session_start();
$templates = array("t1.php","t2.php","t3.php"); #list of templates paths
if (!isset($_SESSION['templates']) || empty($_SESSION['templates'])) {
shuffle($templates); #shuffle them
$_SESSION['templates'] = $templates; #store them in sesssion
}
$currentTemplate = array_pop($_SESSION['templates']); #pops one on each page reload
include $currentTemplate; #includes the next template of the array
#on each page reload an element will be popped out and the next one will be included, the issue, is that sometimes two elements-templates are popped out of the array.
I detected that it pops two elements by the below code:
foreach($_SESSION['templates'] as $key=>$value)
{
echo 'The value of session['."'".$key."'".'] is '."'".$value."'".' <br />';
}
Not reload
The value of session['0'] is 't3.php'
The value of session['1'] is 't2.php'
Reload 1:
On some templates my code works fine, i repeat. I don't know what is going on :)