philip          Mon Jan 20 13:43:41 2003 EDT

  Modified files:              
    /phpdoc/en/reference/http/functions setcookie.xml 
  Log:
  Expand the examples a little, also not rely on register_globals.
  
  
Index: phpdoc/en/reference/http/functions/setcookie.xml
diff -u phpdoc/en/reference/http/functions/setcookie.xml:1.12 
phpdoc/en/reference/http/functions/setcookie.xml:1.13
--- phpdoc/en/reference/http/functions/setcookie.xml:1.12       Wed Nov  6 23:59:54 
2002
+++ phpdoc/en/reference/http/functions/setcookie.xml    Mon Jan 20 13:43:40 2003
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.12 $ -->
+<!-- $Revision: 1.13 $ -->
 <!-- splitted from ./en/functions/http.xml, last change in rev 1.2 -->
   <refentry id="function.setcookie">
    <refnamediv>
@@ -95,9 +95,13 @@
       <title><function>setcookie</function> send examples</title>
       <programlisting role="php">
 <![CDATA[
+<?php
+$value = 'something from somewhere';
+
 setcookie ("TestCookie", $value);
 setcookie ("TestCookie", $value,time()+3600);  /* expire in 1 hour */
-setcookie ("TestCookie", $value,time()+3600, "/~rasmus/", ".utoronto.ca", 1);
+setcookie ("TestCookie", $value,time()+3600, "/~rasmus/", ".example.com", 1);
+?>
 ]]>
       </programlisting>
      </example>
@@ -110,9 +114,11 @@
       <title><function>setcookie</function> delete examples</title>
       <programlisting role="php">
 <![CDATA[
+<?php
 // set the expiration date to one hour ago
 setcookie ("TestCookie", "", time() - 3600);
 setcookie ("TestCookie", "", time() - 3600, "/~rasmus/", ".utoronto.ca", 1);
+?>
 ]]>
       </programlisting>
      </example>
@@ -126,8 +132,14 @@
      <informalexample>
       <programlisting role="php">
 <![CDATA[
-echo $TestCookie;
+<?php
+// Print an individual cookie
 echo $_COOKIE["TestCookie"];
+echo $HTTP_COOKIE_VARS["TestCookie"];
+
+// Another way to debug/test is to view all cookies
+print_r($_COOKIE);
+?>
 ]]>
       </programlisting>
      </informalexample>
@@ -141,14 +153,27 @@
      <informalexample>
       <programlisting role="php">
 <![CDATA[
+<?php
+// set the cookies
 setcookie ("cookie[three]", "cookiethree");
 setcookie ("cookie[two]", "cookietwo");
 setcookie ("cookie[one]", "cookieone");
-if (isset ($cookie)) {
-    while (list ($name, $value) = each ($cookie)) {
-        echo "$name == $value<br>\n";
+
+// after the page reloads, print them out
+if (isset($_COOKIE['cookie'])) {
+    foreach ($_COOKIE['cookie'] as $name => $value) {
+        echo "$name : $value <br />\n";
     }
 }
+
+/* which prints
+
+three : cookiethree
+two : cookietwo
+one : cookieone
+
+*/
+?>
 ]]>
       </programlisting>
      </informalexample>



-- 
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to