Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2. session_start();
  3. class Example{
  4.     /**
  5.      * Inicialize
  6.      */
  7.     public function __construct()
  8.     {
  9.         if(empty($_SESSION['value']))
  10.         {
  11.             $_SESSION['value'] = 0;
  12.         }
  13.        
  14.     }
  15.  
  16.     public function setValue()
  17.     {
  18.         $_SESSION['value']++;
  19.     }
  20.  
  21.     public function getValue($value='')
  22.     {
  23.         return $_SESSION['value'];
  24.     }
  25. }
  26.  
  27.  
  28. $example = new Example;
  29.  
  30. if(isset($_POST['submit']))
  31. {
  32.     $example->setValue();
  33. }
  34.  
  35. ?>
  36.  
  37. <!DOCTYPE html>
  38. <html lang="en">
  39. <head>
  40.     <meta charset="UTF-8">
  41.     <title>Document</title>
  42.     <link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
  43. </head>
  44. <body>
  45.     <div class="container">
  46.         <div class="col-md-4">
  47.             <form action="" method="POST" role="form">
  48.                 <legend>Valor: <?php echo $example->getValue(); ?></legend>
  49.  
  50.                 <button name="submit" value="submit" type="submit" class="btn btn-primary">Depositar</button>
  51.             </form>
  52.         </div>
  53.     </div>
  54. </body>
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement