Essential PHP Security Book Cover
Essential PHP Security by Chris Shiflett
About | Contents | Buy Now | Reviews | Errata | Code
  1. Foreword
  2. Preface
  1. Introduction
  2. Forms and URLs
          ch02.pdf
  3. Databases and SQL
  4. Sessions and Cookies
          ch04.pdf
  5. Includes
  6. Files and Commands
  7. Authentication and Authorization
  8. Shared Hosting
  1. Configuration Directives
  2. Functions
  3. Cryptography
  4. Index

Edit Session Data (edit.php)

(Chapter 8, Shared Hosting - Pg 81-82)

< Back to Code Repository

<?php
 
session_start
();
 
?>
 
<form action="inject.php" method="POST">
 
<?php
 
$path 
ini_get('session.save_path');
$handle dir($path);
 
while (
$filename $handle->read())
{
    if (
substr($filename05) == 'sess_')
    {
        
$sess_data '';
 
        if (
is_readable("$path/$filename"))
        {
            
$sess_data file_get_contents("$path/$filename");
        }
 
        if (!empty(
$sess_data))
        {
            
session_decode($sess_data);
            
$sess_data $_SESSION;
            
$_SESSION = array();
 
            
$sess_name substr($filename5);
            
$sess_name htmlentities($sess_nameENT_QUOTES'UTF-8');
            echo 
"<h1>Session [$sess_name]</h1>";
 
            foreach (
$sess_data as $name => $value)
            {
                if (
is_string($value))
                {
                    
$name htmlentities($nameENT_QUOTES'UTF-8');
                    
$value htmlentities($valueENT_QUOTES'UTF-8');
                    echo 
"<p>
                         
$name:
                         <input type=\"text\"
                         name=\"
{$sess_name}[{$name}]\"
                         value=\"
$value\" />
                         </p>"
;
                }
            }
 
            echo 
'<br />';
        }
    }
}
 
$handle->close();
 
?>
 
<input type="submit" />
</form>
</body>
</html>