Cookie php code not working!

Joined
Oct 18, 2005
Messages
230
Reaction score
0
Points
16
Your Mac's Specs
MacPro 3.1
Can someone tell me why this won't work? I can't understand why it won't install a cookie on my browser! I've tried Safari, Firefox and Opera and no luck on any of them!

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Cookie</title>
</head>

<body>

<?php 

	setcookie("test", 45, time()+(3600));
	echo "This page has loaded correctly! But is thy cookie there!";
	
?>
<br />
<a href="cookie_read.php">Check that cookie!</a>
</body>
</html>

The link is to a page which has been coded to show the value of the cookie but it doesn't display any value! When I check the cookies stored on my browser it isn't there either!

Any ideas as to why it's all going wrong!!!!!

Thanks guys!


Andy
 
Joined
Nov 15, 2011
Messages
948
Reaction score
150
Points
43
Location
Toronto
Your Mac's Specs
MBP 16” M1max 32/1tb and bunch of other mac/apple stuff
you need to out the setcookie call above output or any html tags, whitespace etc. much the same kind of issues can affect this call like the header calls. It's sent with the html headers.

Take that setcookie line and put it up above everything, no whitespace.

ie:
PHP:
<?php setcookie("test", 45, time()+3600); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Cookie</title>
</head>

<body>
This page has loaded correctly! But is thy cookie there!
    <br />
<a href="cookie_read.php">Check that cookie!</a>
</body>
</html>
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Same with me. And safari 4.0.3 does not support PHP
Every browser "supports" PHP since it doesn't actually interact with PHP. PHP is a server side technology - all the heavy lifting is done on the server. It works by interpreting the code and returning the corresponding HTML. For instance, let's take the following PHP code:
Code:
echo "<div id='test'>Hello</div>";
When the page with that code is requested, the PHP interpreter is called on the server, it figures out that you want to echo out a div with some text and sends the following to your browser:
Code:
<div id='test'>Hello</div>
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top