我有一个 WordPress 插件想要创建 cookie,但它不起作用。我真的很感激帮助。
add_shortcode( 'watchlist', 'cwatchlist_short' );
function cwatchlist_short() {
echo '<div class="wrap"><center>';
echo "<form method='POST' action=''";
echo '<p>Please enter the initial of the cryptocurrency or the symbol you want to add to the watchlist!</p> <p>For example: BTC</p>';
echo "<p><input type='text' name='symbol' placeholder='Initials or symbol'>";
echo "<p><input type='submit' value='Submit'>";
echo "</form></center>";
echo '</div>';
if (isset($_POST["symbol"])){
$x = $_COOKIE['xvalue'] + 1;
setcookie( 'xvalue', $x, time() + 108000, COOKIEPATH, COOKIE_DOMAIN );
debugging shows:
Cannot modify header information - headers already sent
by
I really need help.
Thank you
best regards
您无法在短代码函数中设置 cookie,因为标头已由 WordPress 发送。 setcookie() 定义了一个要与其余 HTTP 标头一起发送的 cookie,因此,如果您想设置 cookie 值,则需要在调用之前或期间将其添加到挂钩中。发送头信息 hook.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)