• On Wednesday, 19th February between 10:00 and 11:00 UTC, the forum will go down for maintenance. Read More

How to drop a cookie using php ?

jake3340

Supreme Member
Joined
Nov 20, 2008
Messages
1,439
Reaction score
437
I created a test.html file and put this in it.

Code:
<?php
setcookie("test", "test1", time()+3600);
?>
<html>
<body>
Test
</body>
</html>

Its not working... shouldn't that set the cookie ?

Could someone try it and tell me if it works for them ?
 
Can you provide a link to the file that supposed to drop a cookie?
 
Put that code in an html file running php on the server. Thats the whole file.
 
I created a test.html file and put this in it.

Code:
<?php
setcookie("test", "test1", time()+3600);
?>
<html>
<body>
Test
</body>
</html>

Its not working... shouldn't that set the cookie ?

Could someone try it and tell me if it works for them ?

Since you put php code in an html file, I assume you're not familiar with web programming :o

First you will need a web server to run php file. You'll need this to save you a lot of pain

http://sourceforge.net/projects/xampp/

Download and setup your web server, then put your code in an php file and put that file in your webroot, the default path is

Code:
yourxamppdirectory/htdocs/

Code:
<?php
setcookie("test", "test1", time()+3600);
?>
<html>
<body>
Cookie value: <?php echo $_COOKIE["test"]; ?>
</body>
</html>

You can access the php file from the default location

Code:
http://localhost/yourphpfile.php

The out put should be
Code:
Cookie value: test

Again, these steps are very basic but since you're putting php code in an html, I feel it is necessary to go into details.
 
It doesn't need to be a php file, and yes it is running on a server that allows PHP. Try that code guys its good but its not working.
 
My server allows php in html files, echo tags and other scripts work perfect. Its just that this script is not dropping any cookies, I tried my hosting and wamp still nothing. And IE is not showing any cookies even tho i set it to accept all cookies.
 
Oh damn, it seems to be working now... strange, thanks anyway guys for your help I appreciate it :)
 
Back
Top