当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpResponse::setCookie方法代码示例

本文整理汇总了PHP中HttpResponse::setCookie方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpResponse::setCookie方法的具体用法?PHP HttpResponse::setCookie怎么用?PHP HttpResponse::setCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpResponse的用法示例。


在下文中一共展示了HttpResponse::setCookie方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parseFile

 public static function parseFile(HttpResponse &$_RESPONSE, $file, array $SERVER, array &$_GET, array &$_POST, array &$_COOKIE, array &$_FILES)
 {
     global $PRISM;
     // Restore session?
     if (isset($_COOKIE['PrismSession']) && isset(self::$sessions[$_COOKIE['PrismSession']]) && self::$sessions[$_COOKIE['PrismSession']][0] > time() && self::$sessions[$_COOKIE['PrismSession']][1] == $SERVER['REMOTE_ADDR']) {
         $_SESSION = self::$sessions[$_COOKIE['PrismSession']][2];
         // Sessions only last for one request. We rewrite it later on if needed.
         unset(self::$sessions[$_COOKIE['PrismSession']]);
     }
     // Change working dir to docRoot
     chdir($PRISM->http->getDocRoot());
     $prismScriptNameHash = md5($PRISM->http->getDocRoot() . $file);
     $prismScriptMTime = filemtime($PRISM->http->getDocRoot() . $file);
     clearstatcache();
     // Run script from cache?
     if (isset(self::$scriptCache[$prismScriptNameHash]) && self::$scriptCache[$prismScriptNameHash][0] == $prismScriptMTime) {
         ob_start();
         eval(self::$scriptCache[$prismScriptNameHash][1]);
         $html = ob_get_contents();
         ob_end_clean();
     } else {
         // Validate the php file
         $parseResult = validatePHPFile($PRISM->http->getDocRoot() . $file);
         if ($parseResult[0]) {
             // Run the script from disk
             $prismPhpScript = preg_replace(array('/^<\\?(php)?/', '/\\?>$/'), '', file_get_contents($PRISM->http->getDocRoot() . $file));
             ob_start();
             eval($prismPhpScript);
             $html = ob_get_contents();
             ob_end_clean();
             // Cache the php file
             self::$scriptCache[$prismScriptNameHash] = array($prismScriptMTime, $prismPhpScript);
         } else {
             $eol = "\r\n";
             $html = '<html>' . $eol;
             $html .= '<head><title>Error parsing page</title></head>' . $eol;
             $html .= '<body bgcolor="white">' . $eol;
             $html .= '<center><h4>' . implode("<br />\r\n", $parseResult[1]) . '</h4></center>' . $eol;
             $html .= '<hr><center>PRISM v' . PHPInSimMod::VERSION . '</center>' . $eol;
             $html .= '</body>' . $eol;
             $html .= '</html>' . $eol;
             unset(self::$scriptCache[$prismScriptNameHash]);
         }
     }
     // Should we store the session?
     if (isset($_SESSION) && $_SESSION != '') {
         $sessionID = sha1(createRandomString(128, RAND_BINARY) . time());
         self::$sessions[$sessionID] = array(time() + PRISM_SESSION_TIMEOUT, $SERVER['REMOTE_ADDR'], $_SESSION);
         $_RESPONSE->setCookie('PrismSession', $sessionID, time() + PRISM_SESSION_TIMEOUT, '/', $SERVER['SERVER_NAME']);
     } else {
         if (isset($_COOKIE['PrismSession'])) {
             $_RESPONSE->setCookie('PrismSession', '', 0, '/', $SERVER['SERVER_NAME']);
         }
     }
     unset($_SESSION);
     // Restore the working dir
     chdir(ROOTPATH);
     // Use compression?
     if ($html != '' && isset($SERVER['HTTP_ACCEPT_ENCODING'])) {
         $encoding = '';
         if (strpos($SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false) {
             $encoding = 'x-gzip';
         } else {
             if (strpos($SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
                 $encoding = 'gzip';
             }
         }
         if ($encoding) {
             $_RESPONSE->addHeader('Content-Encoding: ' . $encoding);
             return gzencode($html, 1);
         } else {
             return $html;
         }
     } else {
         return $html;
     }
 }
开发者ID:NochEinKamel,项目名称:PRISM,代码行数:77,代码来源:prism_phpparser.php


注:本文中的HttpResponse::setCookie方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。