I have the following code which will not work
<?php
echo "Hello World";
$string_name = "highspeed";
$string_value ="test";
$expiry_info = time() +40000;
setcookie($string_name, $string_value, $expiry_info);
?> the hello world works but it will not set a cookie.
If I use Cold Fusion the cookie sets right away.
Why will the php cookie not set?
Thanks very much for any help as this is my first PHP code.
[SOLVED] Cookies will not set
Moderator: General Moderators
That worked --!!thanks
However I am still confused. When i used the code alone without any html it works now. But when I use the php code in a PLAIN html page named
faith.php it will not set a cookie. This is confusing. And frustrating.
feyd|use
However I am still confused. When i used the code alone without any html it works now. But when I use the php code in a PLAIN html page named
faith.php it will not set a cookie. This is confusing. And frustrating.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>PHP Trial</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$string_name = "highspeed";
$string_value ="test";
$expiry_info = time() +40000;
setcookie($string_name, $string_value, $expiry_info);
echo "Hello World";
?>
</body>
</html>Code: Select all
tags when posting code please.[/color]Header errors are very irratating especially when you are new to PHP. Try this:
Take feyd's suggestion and goto the tutorials section!
All the best
Joe
Code: Select all
<?php
$string_name = "highspeed";
$string_value ="test";
$expiry_info = time() +40000;
setcookie($string_name, $string_value, $expiry_info);
echo "Hello World";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>PHP Trial</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
HTML CODE HERE. NOT THE COOKIE SET. IT WOULD RESULT IN A HEADER ERROR AS THERE IS OUTPUT BEEN GIVEN!
</body>
</html>All the best
Joe