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
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
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.