简体   繁体   English

以PHP表单提交后如何轻松隐藏回声?

[英]How to easily hide an echo after submit in a PHP form?

I'm working with cookies and I need to show a message saying that 'x' cookie is not set until I introduce a value in a form, then after I click submit I need to show a message saying that 'x' cookie is set, but I need to 'hide' the previous message.我正在使用 cookie,我需要显示一条消息,指出在我在表单中引入一个值之前,未设置 'x' cookie,然后在单击提交后,我需要显示一条消息,指出已设置 'x' cookie ,但我需要“隐藏”之前的消息。

<?php
$cookie_name = NULL;
$cookie_value = NULL;
$cookie_name = "user";
$cookie_value = "Name Surname";

setcookie($cookie_name, $cookie_value, time()+86400 );

echo "Cookie named '" . $cookie_name . "' is not set!";

if($_SERVER["REQUEST_METHOD"]=="POST"){
  if(!isset($_COOKIE[$cookie_name])) {
     echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
     echo "Cookie '" . $cookie_name . "' is set!<br>";
     echo "Value is: " . $_COOKIE[$cookie_name];
 } 
}
?>

Cheers.干杯。

That are basics!那是基础!

$cookie_name = NULL;
$cookie_value = NULL;
$cookie_name = "user";
$cookie_value = "Name Surname";

setcookie($cookie_name, $cookie_value, time()+86400 );

// Inital value of output
$output = "Cookie named {$cookie_name} is not set!";

// Check if method is POST and if cookie is set
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_COOKIE[$cookie_name])) {
    // Overwrite output
    $output = "Cookie {$cookie_name} is set!<br>Value is: {$_COOKIE[$cookie_name]}";
}

// Show output
echo $ouput;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM