Logo  

CS479/579 - Web Programming II

Displaying ./code/PHP_Sessions/two.php

<?php
  session_start();
  if (isset($_POST['todo'])) {
    if (isset($_SESSION['todo']))
      $_SESSION['todo'][] = htmlspecialchars($_POST['todo']);
    else
      $_SESSION['todo'] = [ htmlspecialchars($_POST['todo']) ];
  }
?>
<!DOCTYPE html>
<html>
<head>
 <title> PHP sessions </title>
</head>
<body>
<ul>
<?php
  foreach($_SESSION['todo'] as $todo) {
    echo "<li> {$todo}\n";
  }
?>
</ul>
<form method=post>
 <input type='text' name='todo' placeholder='Something todo'>
 <input type='submit'>
</form>
<a href='three.php'> Reset todo list </a>
<pre>
<?php
  var_dump($_COOKIE);
?>
</pre>
</body>
</html>