Location: PHPKode > scripts > Combine XML, Files and SQLite with PHP 5 > combine-xml-files-and-sqlite-with-php-5/php_publ100608.htm
<html>

<head>
<meta http-equiv="Content-Language" content="de-ch">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Combine XML,Files and SQLite with PHP 5</title>
</head>

<body>

<table border="0" width="100%">
  <tr>
    <td width="100%"><font face="Arial" size="1">Manipulation of parameters, Cross Site Scripting,  SQL Injection, Session hacking - there are many ways to attack a websites integrity for evil purposes (see screenshots <a href="#screenshot">below</a>). This application makes use of several techniques to prevent your web application from harmful code (some of them refer to the excellent book &quot;PHP-Sicherheit&quot;, published by dpunkt.verlag, 2007). Among other features you'll find data type control, control of allowed variables in URI strings, several session and history controls, control of drowdown menus, control of form names and form action URI and controls of forbidden inserts in form elements (fully automated), a generator for safe passwords,  and a consistent use of file_exists(). Besides the PHP 5 functions __autoload for classes and try and catch a special feature is the safeHTML parser (http://pixel-apes.com/safehtml), which helps to remove not desired attributes and tags effective. <br>
					</font>
					<p><font face="Arial" size="1">The scripts snippets you see here (the complete script is <a href="#load">downloadable</a>)&nbsp;is only a small part of the complete application. That's it. The SQLite code for the database action and other stuff is all prepared for your convenience (create-table-, css- and connection-file included). <i>Best regards Claudio Biesele</i></font></p>
				</td>
  </tr>
  <tr>
    <td width="100%">
      <hr>
					<p><font face="Arial" size="1"><b>Part of the PHP Configuration Class Code:</b></font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">class VRConfiguration extends VRException {<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">  const STORE_DB  = 1;<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">  const STORE_SQLite = 2;<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">  const STORE_XML  = 3;<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">  const STORE_FILE  = 4;<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">  public static function getStore($type = self::STORE_XML) {<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">   switch ($type) {<br>
							    </font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;case self::STORE_DB:<br>
							    </font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;return new Configuration_DB();<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;case self::STORE_SQLite:<br>
							    </font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;return new Configuration_SQLite();<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;case self::STORE_XML:<br>
							    </font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;return new Configuration_XML();<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;case self::STORE_FILE:<br>
							    </font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;return new Configuration_FILE();<br>
							   </font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;}</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> <br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">}<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> class ConfigurationDB {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">  // ....<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> }<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> class Configuration_SQLite {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;public $sqlite_config;<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;protected $sqlitefile;<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;function __construct() { <br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;$sqlitefile = 'data/vrcustomer.sqlite';<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;if(!file_exists($sqlitefile) || filesize($sqlitefile) == 0) {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(&quot;&lt;span class=\&quot;mess\&quot;&gt;No access to databse.&lt;/span&gt;&quot;); <br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;}<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;else {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;sqlite_config = new SQLiteDatabase($sqlitefile); <br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return $this-&gt;sqlite_config;<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;} </font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">  } </font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> } </font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> class Configuration_XML {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;public $xml_config;<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;function __construct() {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;$this-&gt;xml_config = $_SERVER[DOCUMENT_ROOT]<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;.'/xxx/MyRentABike/data/det_vehicles.xml';<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;if (!file_exists($this-&gt;xml_config)) {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(&quot;&lt;span class=\&quot;mess\&quot;&gt;File does not exist.\n&lt;/span&gt;&quot;); }<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;else {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return $this-&gt;xml_config;<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;}</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">  }</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> }</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> class Configuration_FILE {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;public $file_config;<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;function __construct() {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;$this-&gt;file_config = $_SERVER[DOCUMENT_ROOT]<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;.'/xxx/MyRentABike/data/fleet.txt';<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;if (!file_exists($this-&gt;file_config)) {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(&quot;&lt;span class=\&quot;mess\&quot;&gt;File does not exist.\n&lt;/span&gt;&quot;); }<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;else {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return $this-&gt;file_config;<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;}</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">  }</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> }</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> </font></p>
				</td>
  </tr>
  <tr>
    <td width="100%">
      <hr>
					<p><font face="Arial" size="1"><b>Part of the XML Handler Class Code:</b></font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">public function getXMLSelLand($land) {<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;$xml = simplexml_load_file($this-&gt;xml);<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;$path =&quot;/root/laender/land&quot;;<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;if (!$res = $xml-&gt;xpath($path)) <br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;{  die(&quot;&lt;span class=\&quot;mess\&quot;&gt;No record found.&lt;/span&gt;&quot;); } <br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;else { <br>
							
							&nbsp;&nbsp;&nbsp;$this-&gt;xmlhtml =&quot;&lt;select name=\&quot;selectLand\&quot; size=\&quot;1\&quot;&gt;&quot;;<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;foreach($res as $val) { <br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;if($val == &quot;Europe&quot; || $val == &quot;USA&quot;) {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;xmlhtml .= &quot;&lt;optgroup label=\&quot;{$val}\&quot;&gt;&quot;; }<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;elseif($land == $val) { <br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;xmlhtml .= &quot;&lt;option selected value=\&quot;{$val}\&quot;&gt;{$val}&lt;/option&gt;&quot;; }<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;else {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;xmlhtml .= &quot;&lt;option value=\&quot;{$val}\&quot;&gt;{$val}&lt;/option&gt;&quot;;<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;}</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">}<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;$this-&gt;xmlhtml .= &quot;&lt;/optgroup&gt;&quot;;<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;$this-&gt;xmlhtml .= &quot;&lt;/select&gt;&quot;;<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;return $this-&gt;xmlhtml; <br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;}</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">}</font></p>
				</td>
  </tr>
  <tr>
    <td width="100%">
      <hr>
    </td>
  </tr>
  <tr>
    <td width="100%">&nbsp;<br>
					<font face="Arial" size="1"><b>Part of the PHP 5 Class DebuggerFile:</b></font>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">class VRDebuggerFile extends VRDebuggerEcho implements Debugger {<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;protected $logfile = null;<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;private static $instances = array();<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;public static function getInstance($logfile) {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;if (!isset(self::$instances[$logfile])) {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self::$instances[$logfile] = new VRDebuggerFile($logfile);<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;}<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;return self::$instances[$logfile];<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;}<br>
							<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;protected function __construct($logfile) {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;logfile = $logfile;<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;}<br>
						</font></p>
					<p><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;private function __clone() {}<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;<br>
							&nbsp;&nbsp;&nbsp;public function debug($message) {<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;error_log(&quot;{$message}\n&quot;, 3, $this-&gt;logfile);<br>
						</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">&nbsp;&nbsp;&nbsp;}</font><font size="1" color="blue" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">}}</font><font size="1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><a name="screenshot"></a><br>
						</font></p>
				</td>
  </tr>
  <tr>
    <td width="100%">
      <hr>
    </td>
  </tr>
  <tr>
    <td width="100%"><img border="0" src="MyRentABike001.jpg" width="475" height="275"></td>
  </tr>
  <tr>
    <td width="100%"><font face="Arial" size="1"><b>1. View:</b> Overview fo the small web application which allows to manage a vehicle fleet.</font></td>
  </tr>
  <tr>
    <td width="100%"><img border="0" src="MyRentABike002.jpg" width="475" height="275"></td>
  </tr>
  <tr>
				<td width="100%"><font face="Arial" size="1"><b>2. View:</b> The basic data for the bicycles is stored in a XML file and is submitted to a text file.</font></td>
			</tr>
  <tr>
    <td width="100%"><img border="0" src="MyRentABike003.jpg" width="475" height="275"></td>
  </tr>
  <tr>
    <td width="100%"><font face="Arial" size="1"><b>3. View:</b> On the same page you can fill up the SQLIte table with customers.</font></td>
  </tr>
  <tr>
    <td width="100%"><img border="0" src="MyRentABike004.jpg" width="475" height="275"></td>
  </tr>
			<tr>
    <td width="100%"><font face="Arial" size="1"><b>4. View:</b> Customers can look at the properties of the bicycles in gerenal and in detail.</font></td>
  </tr>
			<tr>
				<td width="100%"><img src="MyRentABike005.jpg" alt="" height="275" width="475" border="0"></td>
			</tr>
			<tr>
				<td width="100%"><font face="Arial" size="1"><b>5. View:</b> The more complex look at the administration of the vehicle fleet.</font></td>
			</tr>
			<tr>
				<td width="100%"><img src="MyRentABike006.jpg" alt="" height="275" width="475" border="0"></td>
			</tr>
			<tr>
				<td width="100%"><font face="Arial" size="1"><b>6. View:</b> Change the rent start and end date in the text file with the fleet data.</font></td>
			</tr>
			<tr>
				<td width="100%"></td>
			</tr>
			<tr>
    <td width="100%"><font face="Arial" size="1">Download the full script at <a href="http://www.fastproject.ch/publikationen/MyRentABike.rar#load" target="_blank">www.fastproject.ch</a>. The downloaded script is free from Copyright restrictions, Zurich, 10th of June 2008.<a name="load"></a></font></td>
  </tr>
		</table>

</body>

</html>
Return current item: Combine XML, Files and SQLite with PHP 5