⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 language.variables.external.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
📖 第 1 页 / 共 2 页
字号:
     </p>     <div class="informalexample">      <div class="example-contents"><div class="cdata"><pre>&lt;input type=&quot;image&quot; src=&quot;image.gif&quot; name=&quot;sub&quot; /&gt;</pre></div>      </div>     </div>     <p class="simpara">      When the user clicks somewhere on the image, the accompanying      form will be transmitted to the server with two additional      variables, sub_x and sub_y. These contain the coordinates of the      user click within the image.  The experienced may note that the      actual variable names sent by the browser contains a period      rather than an underscore, but PHP converts the period to an      underscore automatically.     </p>    </div>   </div>   <div id="language.variables.external.cookies" class="sect2">    <h3 class="title">HTTP Cookies</h3>    <p class="simpara">     PHP transparently supports HTTP cookies as defined by <a href="http://cgi.netscape.com/newsref/std/cookie_spec.html" class="link external">&raquo; Netscape&#039;s Spec</a>.  Cookies are a     mechanism for storing data in the remote browser and thus     tracking or identifying return users.  You can set cookies using     the <a href="function.setcookie.html" class="function">setcookie()</a> function.  Cookies are part of     the HTTP header, so the SetCookie function must be called before     any output is sent to the browser.  This is the same restriction     as for the <a href="function.header.html" class="function">header()</a> function.  Cookie data      is then available in the appropriate cookie data arrays, such      as <var class="varname"><a href="reserved.variables.cookies.html" class="classname">$_COOKIE</a></var>, <var class="varname">$HTTP_COOKIE_VARS</var>      as well as in <var class="varname"><a href="reserved.variables.request.html" class="classname">$_REQUEST</a></var>.  See the      <a href="function.setcookie.html" class="function">setcookie()</a> manual page for more details and      examples.    </p>    <p class="simpara">     If you wish to assign multiple values to a single cookie variable, you      may assign it as an array.  For example:    </p>    <div class="informalexample">     <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;setcookie</span><span style="color: #007700">(</span><span style="color: #DD0000">"MyCookie[foo]"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Testing&nbsp;1'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">time</span><span style="color: #007700">()+</span><span style="color: #0000BB">3600</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">setcookie</span><span style="color: #007700">(</span><span style="color: #DD0000">"MyCookie[bar]"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Testing&nbsp;2'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">time</span><span style="color: #007700">()+</span><span style="color: #0000BB">3600</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>     </div>    </div>        <p class="simpara">     That will create two separate cookies although MyCookie will now      be a single array in your script.  If you want to set just one cookie      with multiple values, consider using <a href="function.serialize.html" class="function">serialize()</a> or      <a href="function.explode.html" class="function">explode()</a> on the value first.    </p>    <p class="simpara">     Note that a cookie will replace a previous cookie by the same     name in your browser unless the path or domain is different.  So,     for a shopping cart application you may want to keep a counter     and pass this along.  i.e.    </p>    <div class="example">     <p><b>Example #4 A <a href="function.setcookie.html" class="function">setcookie()</a> example</b></p>     <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(isset(</span><span style="color: #0000BB">$_COOKIE</span><span style="color: #007700">[</span><span style="color: #DD0000">'count'</span><span style="color: #007700">]))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$count&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$_COOKIE</span><span style="color: #007700">[</span><span style="color: #DD0000">'count'</span><span style="color: #007700">]&nbsp;+&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$count&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">setcookie</span><span style="color: #007700">(</span><span style="color: #DD0000">'count'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$count</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">time</span><span style="color: #007700">()+</span><span style="color: #0000BB">3600</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">setcookie</span><span style="color: #007700">(</span><span style="color: #DD0000">"Cart[$count]"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$item</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">time</span><span style="color: #007700">()+</span><span style="color: #0000BB">3600</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>     </div>    </div>   </div>   <div id="language.variables.external.dot-in-names" class="sect2">    <h3 class="title">Dots in incoming variable names</h3>    <p class="para">     Typically, PHP does not alter the names of variables when they     are passed into a script. However, it should be noted that the     dot (period, full stop) is not a valid character in a PHP     variable name. For the reason, look at it:     <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$varname</span><span style="color: #007700">.</span><span style="color: #0000BB">ext</span><span style="color: #007700">;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;invalid&nbsp;variable&nbsp;name&nbsp;*/<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>     </div>     Now, what the parser sees is a variable named     <var class="varname">$varname</var>, followed by the string concatenation     operator, followed by the barestring (i.e. unquoted string which     doesn&#039;t match any known key or reserved words) &#039;ext&#039;. Obviously,     this doesn&#039;t have the intended result.    </p>    <p class="para">     For this reason, it is important to note that PHP will     automatically replace any dots in incoming variable names with     underscores.    </p>   </div>   <div id="language.variables.determining-type-of" class="sect2">    <h3 class="title">Determining variable types</h3>    <p class="para">     Because PHP determines the types of variables and converts them     (generally) as needed, it is not always obvious what type a given     variable is at any one time.  PHP includes several functions     which find out what type a variable is, such as:     <a href="function.gettype.html" class="function">gettype()</a>, <a href="function.is-array.html" class="function">is_array()</a>,     <a href="function.is-float.html" class="function">is_float()</a>, <a href="function.is-int.html" class="function">is_int()</a>,     <a href="function.is-object.html" class="function">is_object()</a>, and     <a href="function.is-string.html" class="function">is_string()</a>.  See also the chapter on      <a href="language.types.html" class="link">Types</a>.    </p>   </div>  </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="language.variables.html">Variables</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.constants.html">Constants</a></div> <div class="up"><a href="language.variables.html">Variables</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -