manual/en/features.cookies.php

20031209_rev01 · COMPARED WITH 20030805_rev01 · ARCHIVE SNAPSHOT, DATE APPROXIMATE

Full text changes — 20030805_rev01 to 20031209_rev01

1## Chapter 17. Cookies
1`if ((isset($aid)) && (isset($pwd)) && ($op == "login")) { if($aid!="" AND $pwd!="") { $pwd = md5($pwd); $result=sql_query("select pwd, admlanguage from ".$prefix."_authors where aid='$aid'", $dbi); list($pass, $admlanguage)=sql_fetch_row($result, $dbi); if($pass == $pwd) { $admin = base64_encode("$aid:$pwd:$admlanguage"); setcookie("admin","$admin",time()+3600); unset($op); } } }`
22
3PHP transparently supports HTTP cookies. Cookies are a mechanism for storing data in the remote browser and thus tracking or identifying return users. You can set cookies using the [**setcookie()**](http://www.php.net/manual/en/function.setcookie.php) function. Cookies are part of the HTTP header, so [**setcookie()**](http://www.php.net/manual/en/function.setcookie.php) must be called before any output is sent to the browser. This is the same limitation that [**header()**](http://www.php.net/manual/en/function.header.php) has. You can use the [output buffering functions](http://www.php.net/manual/en/ref.outcontrol.php) to delay the script output until you have decided whether or not to set any cookies or send any headers.
3`$admintest = 0;`
44
5Any cookies sent to you from the client will automatically be turned into a PHP variable just like GET and POST method data, depending on the register\_globals and variables\_order configuration variables. If you wish to assign multiple values to a single cookie, just add _\[\]_ to the cookie name.
6
7In PHP 4.1.0 and later, the $\_COOKIE auto-global array will always be set with any cookies sent from the client. $HTTP\_COOKIE\_VARS is also set in earlier versions of PHP when the track\_vars configuration variable is set.
8
9For more details, including notes on browser bugs, see the [**setcookie()**](http://www.php.net/manual/en/function.setcookie.php) function.
10
11<table><tbody><tr><td><small>User Contributed Notes</small><br><b>Cookies</b></td><td><a href="http://www.php.net/manual/add-note.php?sect=features.cookies&amp;redirect=http://www.php.net/manual/en/features.cookies.php"><img src="http://static.php.net/www.php.net/images/notes-add.gif" alt="add a note" width="13" height="13"></a> <small><a href="http://www.php.net/manual/add-note.php?sect=features.cookies&amp;redirect=http://www.php.net/manual/en/features.cookies.php">add a note</a></small></td></tr><tr><td colspan="2"><a name="#34157"></a><table><tbody><tr><td><b>wilton at intertranet dot com</b><br>17-Jul-2003 05:14</td><td><br></td></tr><tr><td colspan="2"><code>if ((isset($aid)) &amp;&amp; (isset($pwd)) &amp;&amp; ($op == "login")) {<br>&nbsp; &nbsp;if($aid!="" AND $pwd!="") {<br>$pwd = md5($pwd);<br>$result=sql_query("select pwd, admlanguage from ".$prefix."_authors where aid='$aid'", $dbi);<br>list($pass, $admlanguage)=sql_fetch_row($result, $dbi);<br>if($pass == $pwd) {<br>&nbsp; &nbsp;$admin = base64_encode("$aid:$pwd:$admlanguage");<br>&nbsp; setcookie("admin","$admin",time()+3600);<br>&nbsp; unset($op);<br>}<br>&nbsp; &nbsp;}<br>}<p>$admintest = 0;</p><p>if(isset($admin) &amp;&amp; $admin != "") {<br>$admin = base64_decode($admin);<br>&nbsp;$admin = explode(":", $admin);<br>&nbsp;$aid = "$admin[0]";<br>&nbsp;$pwd = "$admin[1]";<br>&nbsp;$admlanguage = "$admin[2]";<br>&nbsp;if ($aid=="" || $pwd=="") {<br>&nbsp; &nbsp;$admintest=0;<br>&nbsp; echo "&lt;html&gt;\n";<br>&nbsp; &nbsp;echo "&lt;title&gt;Ingreso prohibido&lt;/title&gt;\n";<br>&nbsp; &nbsp;echo "&lt;body bgcolor=\"#FFFFFF\" text=\"#000000\"&gt;\n\n</p><p>\n\n";<br>&nbsp; &nbsp;echo "&lt;center&gt;&lt;img src=\"images/logo.gif\" border=\"0\"&gt;</p><p>\n";<br>&nbsp; &nbsp;echo "&lt;font face=\"Verdana\" size=\"+4\"&gt;&lt;b&gt;Su Ip esta siendo registrada en nuestra base de datos, toda operaci�n indebida ser� investigada.</p><p>Gerencia Administrativa&lt;/b&gt;&lt;/font&gt;&lt;/center&gt;\n";<br>&nbsp; &nbsp;echo "&lt;/body&gt;\n";<br>&nbsp; &nbsp;echo "&lt;/html&gt;\n";</p></code><br></td></tr></tbody></table></td></tr><tr><td colspan="2"><a href="http://www.php.net/manual/add-note.php?sect=features.cookies&amp;redirect=http://www.php.net/manual/en/features.cookies.php"><img src="http://static.php.net/www.php.net/images/notes-add.gif" alt="add a note" width="13" height="13"></a> <small><a href="http://www.php.net/manual/add-note.php?sect=features.cookies&amp;redirect=http://www.php.net/manual/en/features.cookies.php">add a note</a></small></td></tr></tbody></table>
5`if(isset($admin) && $admin != "") { $admin = base64_decode($admin); $admin = explode(":", $admin); $aid = "$admin[0]"; $pwd = "$admin[1]"; $admlanguage = "$admin[2]"; if ($aid=="" || $pwd=="") { $admintest=0; echo "<html>\n"; echo "<title>Ingreso prohibido</title>\n"; echo "<body bgcolor=\"#FFFFFF\" text=\"#000000\">\n\n<br><br><br>\n\n"; echo "<center><img src=\"images/logo.gif\" border=\"0\"><br><br>\n"; echo "<font face=\"Verdana\" size=\"+4\"><b>Su Ip esta siendo registrada en nuestra base de datos, toda operaci�n indebida ser� investigada.<br><br><br>Gerencia Administrativa</b></font></center>\n"; echo "</body>\n"; echo "</html>\n";`