papaface Posted December 30, 2007 Share Posted December 30, 2007 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 More sharing options...
Orio Posted December 30, 2007 Share Posted December 30, 2007 Are you sure you have session_start() on the top of your pages? Orio. Link to comment https://forums.phpfreaks.com/topic/83743-solved-multi-dimensional-array-sessions/#findComment-426087 Share on other sites More sharing options...
papaface Posted December 30, 2007 Author Share Posted December 30, 2007 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 https://forums.phpfreaks.com/topic/83743-solved-multi-dimensional-array-sessions/#findComment-426090 Share on other sites More sharing options...
papaface Posted December 30, 2007 Author Share Posted December 30, 2007 Ahh found the problem and its not with sessions, its to do with my class. Link to comment https://forums.phpfreaks.com/topic/83743-solved-multi-dimensional-array-sessions/#findComment-426096 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.