Source for file 10.php

Documentation is available at 10.php

  1. <?php
  2. /*
  3. * This file is part of Sylar.
  4. *
  5. * Sylar is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Sylar is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with Sylar. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * @copyright Copyright Sylar Development Team
  19. * @license http://www.gnu.org/licenses/ GNU Public License V2.0
  20. * @see https://launchpad.net/sylar/
  21. * @see http://www.giano-solutions.com
  22. */
  23.  
  24. /**
  25. * Example Sylar File
  26. * Some files that shows how sylar works
  27. *
  28. * @package Sylar
  29. * @version 1.0
  30. * @since 02-2008
  31. * @author Gianluca Giusti [brdp] <g.giusti@giano-solutions.com>
  32. * @copyright Sylar Development Team
  33. */
  34.  
  35. #
  36. # Include the bas Application settings
  37. #
  38.  
  39. require_once 'config/appConfig.php';
  40.  
  41. import('sylar.common.security.Cookie');
  42. import('sylar.presentation.html.HtmlPage');
  43.  
  44.  
  45. try{
  46. $txt = "";
  47. // Cookie Test object
  48. $ck = new Sylar_Cookie();
  49. // Set a magic cookie that persist until the end of browser session
  50. $cookieKey = "Sylar_TEST_1";
  51. if($ck->exists($cookieKey)){
  52. $txt .= "<br><br><i>Magic Cookie exists</i>: <b>".$ck->get($cookieKey)."</b>";
  53. }else{
  54. $ck->set($cookieKey, rand(1, 9999999));
  55. $txt .= "<br><br><i>Magic Cookie does not exists. Created! </i> <b>".$ck->get($cookieKey)."</b>";
  56. }
  57. // Set a prefix for cookie name
  58. $ck->setKeyPrefix("Sylar___");
  59. // Set cookie that persist for 30 seconds
  60. $cookieKey = "TEST_2";
  61. if($ck->exists($cookieKey)){
  62. $txt .= "<br><br><i>Cookie exists with prefix Sylar___ and persists for 30 seconds then reload the page! Value</i>: <b>".$ck->get($cookieKey)."</b>";
  63. }else{
  64. $ck->set($cookieKey, rand(1, 9999999), time()+30);
  65. $txt .= "<br><br><i>Cookie does not exists. Created! </i> <b>".$ck->get($cookieKey)."</b>";
  66. }
  67. // Set a path on the server, the prefix is still set
  68. $ck->setPathOnServer("/");
  69. // Set a cookie that persist for 50 seconds in page contained in path /
  70. $cookieKey = "TEST_3";
  71. if($ck->exists($cookieKey)){
  72. $txt .= "<br><br><i>Cookie exists on server from path / with prefix Sylar___ and it persists for 50 seconds then reload the page! Value</i>: <b>".$ck->get($cookieKey)."</b>";
  73. }else{
  74. $ck->set($cookieKey, rand(1, 9999999), time()+50);
  75. $txt .= "<br><br><i>Cookie does not exists. Created! </i> <b>".$ck->get($cookieKey)."</b>";
  76. }
  77. // Set and remove a cookie
  78. $cookieKey = "TEST_4_TO_REMOVE";
  79. if($ck->exists($cookieKey)){
  80. $txt .= "<br><br><i>Cookie exists on server</i>: <b>".$ck->get($cookieKey)."</b> Now will be removed.";
  81. $ck->delete($cookieKey);
  82. }else{
  83. $ck->set($cookieKey, rand(1, 9999999));
  84. $txt .= "<br><br><i>Cookie does not exists. Created! </i> <b>".$ck->get($cookieKey)."</b>";
  85. }
  86.  
  87. // Show all cookies name and values
  88. $txt .= "<br><hr><br>";
  89. foreach ($_COOKIE as $k => $v) {
  90. $txt .= "<br>".$k." = ".$v;
  91. }
  92. // Link to next example page
  93. $txt .= "<br><br><br><br><a href='11.php'>Mail sender example &raquo;</a>";
  94. // Prepare Head and Body
  95. $oHH = new Sylar_HtmlHead("Giano Cookie Test page");
  96. $oHH->addMetaTag("text/html; charset=".APP_DEFAULT_CHARSET, null, "content-type");
  97.  
  98. // prepare Body
  99. $oHB = new Sylar_HtmlBody();
  100.  
  101. // Create a DIV
  102. $div = new Sylar_HtmlDiv("test");
  103. // add div content
  104. $div->appendContent($txt);
  105. // append div in the body
  106. $oHB->addDiv($div);
  107. // Then Push into the page Object
  108. $oHP = new Sylar_HtmlPage();
  109. $oHP->setPageHead($oHH);
  110. $oHP->setPageBody($oHB);
  111. // render Html Page
  112. $oHP->show();
  113.  
  114. } catch (ExceptionInSylar $ex){
  115. echo $ex->getMessage();
  116. }
  117.  
  118.  
  119. ?>

Documentation generated on Thu, 24 Apr 2008 16:14:13 +0200 by phpDocumentor 1.3.0RC3