I work a small project to understand the superglobal variable $_SESSION. The current part im at is on page two under the comment " //- Use a foreach loop to display all session cookie names and values.". I don't understand the array to string conversion notice, that I am getting. Also, on my end, I am getting multiple values that are not in the code as well. I've seen a few other questions, but I'm new and I'm not connecting the dots on why this is happening.
I appreciate the help.
Joshua
screen of results
PAGE ONE:
<?php
session_start();
?>
<!DOCTYPE html>
<html lang='en' dir='ltr'>
<head>
<meta charset='utf-8'>
<title>Module 7 -- Page One</title>
<link rel='stylesheet' href='main.css'>
</head>
<body>
<main>
<?php
echo "<h1 class='text_align_center'> Page One:</h1>";
echo "<hr><br>";
//TODO:
//- Start a session and display the session ID.
$lifetime = 0;
session_set_cookie_params($lifetime, '/');
$id = session_id();
echo 'Your session ID: ' . $id . '.';
//- Assign the string 'Hello world' as a session cookie. You pick the key for this element.
$_SESSION['greeting'] = "Hello World";
echo "<br> <br>";
//- Then use the $_SESSION array to display the string in this latter cookie.
echo 'The content of $_SESSION[\'greeting\'] is "' . $_SESSION['greeting'] . '".';
//- Assign two more ssession cookies(You make up the keys and values), dont display.
$_SESSION['greeting2'] = "Hello World the second time!";
$_SESSION['greeting3'] = "Hello World the third time!";
echo "<br> <br>";
echo 'Two more elements were added to $_SESSION!';
echo "<br> <br>";
?>
<!-- //- Add an HTML hyperlink that will excute page2.php when clicked. -->
Procede to <a href="page2.php">Page Two</a>.
</main>
<footer class='text_align_center'>
<hr> <small> SomeWebsite © -- <?php echo date('M.jS.Y'); ?> </small>
</footer>
</body>
</html>
PAGE TWO:
<?php
session_start();
?>
<!DOCTYPE html>
<html lang='en' dir='ltr'>
<head>
<meta charset='utf-8'>
<title>Module 7 -- </title>
<link rel='stylesheet' href='main.css'>
</head>
<body>
<main>
<?php
echo "<h1 class='text_align_center'> Page Two:</h1>";
echo "<hr><br>";
//TODO:
//- Assign 'Murach' to another element of $_SESSION. Use the key 'publisher'.
$_SESSION['Publisher'] = 'Murach';
//- Delete the cookie that stored 'Hello world'.
unset($_SESSION['greeting']);
//- Use a foreach loop to display all session cookie names and values.
foreach ($_SESSION as $key => $value) {
echo 'The current key is: ' . $key;
echo '<br>';
echo 'The current value is: ' . $value;
echo'<br> <br>';
}
echo '<br><br>';
?>
<!-- //- Add another hyperlink that will execute page3.php when clicked. -->
Procede to <a href="page3.php">Page Three</a>.
</main>
<footer class='text_align_center'>
<hr> <small> SomeWebsite © -- <?php echo date('M.jS.Y'); ?> </small>
</footer>
</body>
</html>