I'm having a problem with a web-based application I'm writing. The app requires several PHP session variables. One of the frames contains the following lines which start a check for the variables:
session_start();
require('setup.php');Here is setup.php:
<?php
if( !isset( $_SESSION['size'] ) )
{
$_SESSION['size'] = 32;
}
if( !isset( $_SESSION['map'] ) )
{
$_SESSION['map'] = array();
$_SESSION['map'][] = "...........";
$_SESSION['map'][] = "...........";
$_SESSION['map'][] = "...........";
$_SESSION['map'][] = "...........";
$_SESSION['map'][] = "...........";
$_SESSION['map'][] = "...........";
$_SESSION['map'][] = "...........";
$_SESSION['map'][] = "...........";
$_SESSION['map'][] = "...........";
$_SESSION['map'][] = "...........";
$_SESSION['map'][] = "...........";
}
if( !isset( $_SESSION['undo'] ) )
{
$_SESSION['undo'] = array();
array_push( $_SESSION['undo'], $_SESSION['map'] );
}
//if( !isset( $_SESSION['numbers'] ) )
//{
//
$_SESSION['numbers'] = array();
//}
?>When certain actions are carried out, the function addUndo() is triggered:
<?php
function addUndo()
{
array_push( $_SESSION['undo'], $_SESSION['map'] );
}
?>The problem is that the first time you open the app after loading the browser, the setup appears to work but the next time addUndo() is triggered, the following error is produced:
Warning: array_push() [function.array-push]: First argument should be an array in /Library/WebServer/Documents/undo.php on line 5
If you reload the page, then the map (produced from $_SESSION['map']) is empty. There is a button on the toolbar to create a new file, which basically destroys the session with session_destroy() and then reloads the main page, which then starts a new session, re-triggers the checks in setup.php, re-creates the session variables, and then it works.
Any ideas why it's not working from the start?
TIA