PHP ?? ???(?? ? ??, ????, ??)
Jul 25, 2016 am 08:56 AM
本文介紹下,一個功能強大的php cookie操作類,可以完成設(shè)置cookie、獲取cookie值、刪除cookie值等操作,有需要的朋友參考下。
分享一個php cookie操作的類,可以設(shè)置cookie、獲取cookie、刪除cookie。 代碼: <?php /** * php cookie類 * class:PHP_COOKIE * by bbs.it-home.org */ class PHP_COOKIE { var $_name = ""; var $_val = array(); var $_expires; var $_dir = '/';// all dirs var $_site = ''; function PHP_COOKIE($cname, $cexpires="", $cdir="/", $csite="") { $this->_name=$cname; if($cexpires){ $this->_expires=$cexpires; } else{ $this->_expires=time() + 60*60*24*30*12; // ~12 months } $this->_dir=$cdir; $this->_site=$csite; $this->_val=array(); $this->extract(); } function extract($cname="") { if(!isset($_COOKIE)){ global $_COOKIE; $_COOKIE=$GLOBALS["HTTP_COOKIE_VARS"]; } if(empty($cname) && isset($this)){ $cname=$this->_name; } if(!empty($_COOKIE[$cname])){ if(get_magic_quotes_gpc()){ $_COOKIE[$cname]=stripslashes($_COOKIE[$cname]); } $arr=unserialize($_COOKIE[$cname]); if($arr!==false && is_array($arr)){ foreach($arr as $var => $val){ $_COOKIE[$var]=$val; if(isset($GLOBALS["PHP_SELF"])){ $GLOBALS[$var]=$val; } } } if(isset($this)) $this->_val=$arr; } // 在全局范圍內(nèi)移除cookie unset($_COOKIE[$cname]); unset($GLOBALS[$cname]); } function put($var, $value) { $_COOKIE[$var]=$value; $this->_val["$var"]=$value; if(isset($GLOBALS["PHP_SELF"])){ $GLOBALS[$var]=$value; } if(empty($value)){ unset($this->_val[$var]); } } function clear() { $this->_val=array(); } function set() { if(empty($this->_val)){ $cookie_val=""; } else { $cookie_val=serialize($this->_val); } if(strlen($cookie_val)>4*1024){ trigger_error("The cookie $this->_name exceeds the specification for the maximum cookie size. Some data may be lost", E_USER_WARNING); } setcookie("$this->_name", $cookie_val, $this->_expires, $this->_dir, $this->_site); } } ?> 調(diào)用示例: 1,設(shè)置cookie <?php //cookie操作類 include("class.cookie.php"); // Create a local object $PHP_COOKIE=new PHP_COOKIE("test_cookie"); // Add the variables to be saved in the cookie $PHP_COOKIE->put("namefirst","Jo"); $PHP_COOKIE->put("namelast","Foo"); $PHP_COOKIE->put("number","1234"); $PHP_COOKIE->put("time",time()); // Set the cookie $PHP_COOKIE->set(); $PHP_COOKIE=new PHP_COOKIE("test_cookie 123"); // Add the variables to be saved in the cookie $PHP_COOKIE->put("namefirst","Jo123"); $PHP_COOKIE->put("namelast","Foo13"); $PHP_COOKIE->put("number","123413"); // Set the cookie $PHP_COOKIE->set(); echo "<br>The values saved in the cookie test_cookie are:"; echo "<br>namefirst: = $_COOKIE[namefirst]"; echo "<br>namelast: = $_COOKIE[namelast]"; echo "<br>number: = $_COOKIE[number]"; echo "<br>time: = $_COOKIE[time]"; echo "<br><br>END"; ?> 2,獲取cookie <?php include("class.cookie.php"); //獲取cookie //從保存的cookie中解析變量,然后加入自己的cookies中 PHP_COOKIE::extract("test_cookie"); //顯示cookie echo "<BR>顯示用于測試的一些cookie值" ; echo "<br> Name: "; echo $_COOKIE['namefirst']; echo " "; echo $_COOKIE['namelast']; echo "<br> Number: "; echo $_COOKIE['number']; echo "<br> Time: "; echo $_COOKIE['time']; echo "<br><br>END"; ?> 3,刪除cookie <?php include("class.cookie.php"); //刪除cookie //方法1. 設(shè)置cookie過期時間 //方法2. 調(diào)用 clear()與 set()方法 // Create a local object $PHP_COOKIE=new PHP_COOKIE("test_cookie", time()-86400); // Set the cookie $PHP_COOKIE->set(); // Clear all values #$PHP_COOKIE->clear(); ?> |

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

PHP ?? ??? ?? ???? ?? ? ????? ??? ?????. 1. ?? ??? ??? ??? ??? ? ? ??? ??? ??? ?? ?? ??? ???? ???????. 2. ?? ??? ???? ???? ? ?? ????? ?? ?? ?? ??? ?????. 3. $ _get ? $ _post? ?? Hyperglobal ??? ?? ???? ?? ??? ? ??? ??? ??????? ???????. 4. ?? ?? ?? ???? ?? ?? ?? ??? ?????? ?? ??? ??? ?? ??? ???????. ??? ??? ????? ??? ??? ?? ???? ????? ? ??? ? ? ????.

PHP ?? ???? ???? ????? ?? ? ??? ???? ?? ?? ? ??? ???? ?? ??? ?????? ??? ??? ? ? ???????. 1. ??? ?? CSRF? ???? ?? ??? ??? ???? ?????? ??? ???? FINFO_FILE? ?? ?? MIME ??? ?????. 2. ??? ??? ??? ???? ??? ?? ??? ?? ? WEB ????? ??? ???? ??????. 3. PHP ?? ??? ?? ? ?? ???? NGINX/APACHE? ??? ????? ?? ???? ?????. 4. GD ?????? ??? ? ?? ???? ??? ?? ??? ?? ????.

PHP ?? ???? ? ?? ???? ??? ????. 1. // ?? #? ???? ? ?? ??? ???? // ???? ?? ????. 2. ?? /.../ ?? ?? ?? ??? ????? ?? ? ?? ??? ?? ? ? ????. 3. ?? ?? ?? / if () {} /? ?? ?? ??? ????? ??? ?? ?? ?? ??? ???? ????? ???? ??? ?? ???? ???? ??? ? ??? ??????.

PHP ??? ???? ??? ??? ??? ????? ????. ??? ????? ?? ???? ??? "?? ? ?"??? "?"? ???????. 1. ??? ? ??? ??? DocBlock (/*/)? ?? ?? ??? ???? ??? ? ?? ???? ??????. 2. JS ??? ???? ?? ???? ??? ?? ??? ??? ?????. 3. ??? ?? ?? ?? ??? ???? ????? ????? ???? ?? ????? ???? ? ??????. 4. Todo ? Fixme? ????? ???? ? ? ??? ??? ???? ?? ?? ? ??? ???????. ??? ???? ?? ??? ??? ?? ?? ?? ???? ???? ? ????.

Ageneratorinphpisamemory- ???? Way-Erate-Overgedatasetsetsbaluesoneatimeatimeatimeatimallatonce.1.generatorsuseTheyieldKeywordTocroadtOpvaluesondemand, RetingMemoryUsage.2

tolearnpheffectical, startBysetTupaloCalserErverEnmentUsingToolslikexamppandacodeeditor -likevscode.1) installxamppforapache, mysql, andphp.2) useacodeeditorforsyntaxsupport.3)) 3) testimplephpfile.next, withpluclucincludechlucincluclucludechluclucled

PHP??? ???? ??? ?? ?? ????? ???? ??? ?? ??? ??? ?? ? ??? ??? ???? ?????. ???? 0?? ???? ?? ??? ???? ? ?? ???? ?? ?? ? ? ????. MB_SUBSTR? ?? ??? ??? ???????. ? : $ str = "hello"; echo $ str [0]; ?? H; ??? MB_SUBSTR ($ str, 1,1)? ?? ??? ??? ??? ??????. ?? ???????? ???? ??? ???? ?? ???? ?? ?? ???? ?????? ??? ????? ?? ??? ?? ??? ???? ???? ?? ????.

toinstallphpquickly, usexampponwindowsorhomebrewonmacos.1. ??, downloadandinstallxAmpp, selectComponents, startApache ? placefilesinhtdocs.2
