2

I'm trying to print a list of values that I've stored in a session-variable array, and all I'm getting is that 'Headers already sent...' error. On the error page I can see the array working, but obviously it won't proceed from there. The line the error mentions is this:

$uploadedfiles = print_r($_SESSION['uploadedfiles']);

The array is declared and values are added to it with this:

array_push($_SESSION['uploadedfiles'], $file_name);

Any thoughts?

Thanks kindly.

0

1 Answer 1

5

print_r() will automatically print to the screen. You need to set the second parameter to true to actually capture it in a variable.

$uploadedfiles = print_r($_SESSION['uploadedfiles'], true);
Sign up to request clarification or add additional context in comments.

1 Comment

Specifically, any output to the browser will set the headers, so if you have header() called after that, you'll get that error.

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.