1

I'm a little confused with the following part of my script...

The variables $username and $password are coming from POST form and are ok.

session_start();

$errors = array();

if (empty($username) === true || empty($password) === true) {
    $errors[] = 'You need to enter a username and password!';
    $_SESSION['Errors'] = $errors;
} else if (user_exists($username) === false) {
    $errors[] = 'We can\'t find the username! Have you registered?';
    $_SESSION['Errors'] = $errors;
} else if (user_active($username) === false) {
    $errors[] = 'You haven\'t activated your account!';
    $_SESSION['Errors'] = $errors;
}

When I try to store any $errors[ ] variables in the session, the only value I find in the session variable is just "Array"...

But when I write the variable $errors (without [ ]) then it works...

How can I add in this case one or multiple dynamically stacked array variables to $_SESSION['Errors']?

It's probably simple, but I couldn't find any solution yet in the Internet.

Thank you very much in advance.

0

1 Answer 1

2

Try using print_r or var_dump since it is an array. Using echo will just produce Array

print_r($_SESSION['Errors']); //this
var_dump($_SESSION['Errors']); //or this
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.