<?php
// PHP setcookie Action ... partner to receiver_of_cookie.php
// RJM Programming - April, 2019
// Thanks to https://www.php.net/manual/en/function.setcookie.php
if (isset($_GET['name'])) {
  $name = str_replace('+', ' ', urldecode($_GET['name']));
} else if (isset($_POST['name'])) {
  $name = str_replace('+', ' ', urldecode($_POST['name']));
} else {
  $name = 'TestCookie';
}
if (isset($_GET['value'])) {
  $value = str_replace('+', ' ', urldecode($_GET['value']));
  $domain = (substr(($_SERVER['HTTP_HOST'] . "         "),0,9) != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
  setcookie($name, $value, time()+3600, "/", $domain, false);
  //header('Location: receiver_of_cookie.php');
  $name = "";
  $value = "";
} else if (isset($_POST['value'])) {
  $value = str_replace('+', ' ', urldecode($_POST['value']));
  $domain = (substr(($_SERVER['HTTP_HOST'] . "         "),0,9) != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
  setcookie($name, $value, time()+3600, "/", $domain, false);
  //header('Location: receiver_of_cookie.php');
  $name = "";
  $value = "";
} else {
  $value = 'something from somewhere';
}

echo "<html><body><h1>PHP setcookie Action</h1><h3>RJM Programming - April, 2019</h3><h4>Thanks to <a target=_blank title='PHP setcookie help, thanks' href='https://www.php.net/manual/en/function.setcookie.php'>https://www.php.net/manual/en/function.setcookie.php</a></h4><form method=GET action=./sender_of_cookie.php>
<input name=name type=text placeholder='Cookie name can go here' style=inline-block; value=\"" . $name . "\"></input>&nbsp;<input name=value type=text placeholder='Cookie value can go here' style=inline-block; value=\"" . $value . "\"></input><br><br>
<input type=submit value='Show Below' style='background-color:yellow;'></input></form><br><br>
<iframe src='./receiver_of_cookie.php' style='width:100%;height:600px;'></iframe>
</body>
</html>";
?>
