FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Code to create a cookie in PHP
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Code to create a cookie in PHP [message #169826 is a reply to message #169825] Mon, 27 September 2010 19:36 Go to previous messageGo to previous message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma:
Senior Member
On Sep 27, 8:18 pm, MikeB <mpbr...@gmail.com> wrote:
> Now that I can delete cookies, I'd like to create cookies, but this code
> fails to create a cookie. Can anyone help me by telling me what is
> wrong, please?
>
> -MikeB
>
> <?php
>      $name = "headercookie";
>      $value = "MikeB set this in the header";
>      $expire = time() * 24 * 60 * 60;
>      $path = '/';
>      $domain = "localhost";
>      setcookie($name, $value, $expire);
> ?>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
>      <head>
>          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
>          <title> Set cookies</title>
>      </head>
>      <body>
>          <?php
>   if (isset($_COOKIE)) {
>              echo '<br />First $_COOKIE<pre>';
>              print_r($_COOKIE);
>              echo "</pre>";
>          } else {
>              echo "<br />No cookies here!";
>          }
>          Echo "<br />Now setting my own cookie!";
>          $name = "headercookie";
>          $value = "MikeB set this in the body";
>          $expire = time() * 24 * 60 * 60;
>          $path = '/';
>          $domain = "localhost";
>          setcookie($name, $value, $expire);
>          if (isset($_COOKIE)) {
>              echo '<br />Second $_COOKIE<pre>';
>              print_r($_COOKIE);
>              echo "</pre>";
>          }
>          ?>
>      </body>
> </html>

Mike, it's nice that you're keen, but if you slow down a bit and start
from the examples in the manual, changing them step by step, you'll
get on a lot better that just throwing some code down and asking here
when it doesn't work.

Try the Example #1 from

http://uk.php.net/manual/en/function.setcookie.php

and then note that you are multiplying the time() value rather than
adding to it.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: mysql_fetch_array
Next Topic: Route/Link to an action works with http, but NOT with httpS (SSL!)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Oct 20 01:24:32 GMT 2024

Total time taken to generate the page: 0.04927 seconds