我正在学习php。我遵循了 php 手册中的示例代码,但它给了我这个警告。
<?php
$value = 'something from somewhere';
setcookie("TestCookie", $value);
setcookie('TestCookie', $value, time() + 3600);
setcookie("TestCookie", $value, time() + 3600, "/~rasmus/", "example.com",1);
?>
The cookies have been set.
<?php
echo 'part 1';
echo $_COOKIE["TestCookie"];
echo 'part 2';
echo $HTTP_COOKIE_VARS['TestCookie'];
echo 'part 3';
print_r($_COOKIE);
?>
但输出给了我这个警告。任何人都可以帮忙吗?谢谢 !
( ! ) Warning: Cannot modify header information - headers already sent by (output started at /home/tqjustc/Documents/Workspace/PHP/public_html/demo_PHP/demo1.php:2) in /home/tqjustc/Documents/Workspace/PHP/public_html/demo_PHP/demo1.php on line 5
Call Stack
# Time Memory Function Location
1 0.0001 631440 {main}( ) ../demo1.php:0
2 0.0001 632176 setcookie ( ) ../demo1.php:5
( ! ) Warning: Cannot modify header information - headers already sent by (output started at /home/tqjustc/Documents/Workspace/PHP/public_html/demo_PHP/demo1.php:2) in /home/tqjustc/Documents/Workspace/PHP/public_html/demo_PHP/demo1.php on line 6
Call Stack
# Time Memory Function Location
1 0.0001 631440 {main}( ) ../demo1.php:0
2 0.0002 632256 setcookie ( ) ../demo1.php:6
( ! ) Warning: Cannot modify header information - headers already sent by (output started at /home/tqjustc/Documents/Workspace/PHP/public_html/demo_PHP/demo1.php:2) in /home/tqjustc/Documents/Workspace/PHP/public_html/demo_PHP/demo1.php on line 7
Call Stack
# Time Memory Function Location
1 0.0001 631440 {main}( ) ../demo1.php:0
2 0.0002 632624 setcookie ( ) ../demo1.php:7
The cookies have been set. part 1part 2part 3Array ( [PHPSESSID] => 81990884013fa394c95c38b7f6aeac6e )