Jump to content

[SOLVED] Multi-Dimensional Array (sessions)


papaface

Recommended Posts

Hello,

I am trying to create a new element in the sessions array like this:

$_SESSION['lerror'][] = "Username not registered.";

The idea is that I will be able to do:

	if	($_SESSION['lerror'])
	{
	foreach	($_SESSION['lerror'] as $key => $value)
		{
		echo $value . "<br />";
		}
	}

To extract the errors, but for some reason this $_SESSION['lerror'][]  isn't creating a $_SESSION['lerror'] session. Is there something I am doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/83743-solved-multi-dimensional-array-sessions/
Share on other sites

Yeah I definately do. It is in an included file at the top of my page called "constants.php":

Maybe if I supply the code for the page you may see something:

<?php
include("includes/constants.php");
if ($_POST['submit'])
{    //include(CreatePath("templates/checkloginform.php"));

include(CreatePath("includes/memberfunctions.php"));

if	(!$_mem->LoginCheckUsername($_POST['username']))
	{
	$_SESSION['lerror'][] = "Username not registered.";
	}
if	(!$_mem->LoginCheckPassword($_POST['password']))
	{
	$_SESSION['lerror'][] = "You have entered an incorrect password. Please try again.";
	}
if	($_SESSION['lerror'])
	{
  		header('Location: '.CreateURL("login2.php"));
	}
else
	{
            if	(!$_mem->Login())
            	{
            	header('Location: '.CreateURL("login2.php?error=nli"));//not logged in (problem)
            	}
          	else
          		{
          		$_loggedin = 1;
          		}
	}


}
//Begin Output
include(CreatePath("templates/header.php"));
if	($_loggedin == 1)
{	echo "You are now logged in.";
}
else if	($_SESSION['loggedin'] == 1)
{
echo "You are already logged in.";
}
else
{	include(CreatePath("templates/loginform2.php"));
}
include(CreatePath("templates/footer.php"));
print_r($_SESSION);
//Output ends
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.