ultimix
security.php
Go to the documentation of this file.
1 <?php
2 
3  /*
4  * This source code is a part of the Ultimix Project.
5  * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6  * it's own license wich could be found from the corresponding files or sources.
7  * This source code is provided "as is" without any warranties or garanties.
8  *
9  * Have a nice day!
10  *
11  * @url http://ultimix.sorceforge.net
12  *
13  * @author Alexey "gdever" Dodonov
14  */
15 
27 
38  var $SecurityUtilities = false;
39  var $Settings = false;
40  var $String = false;
41  var $SupportedDataTypes = false;
42 
53  function __construct()
54  {
55  try
56  {
57  if( session_id() == '' )
58  {
59  @session_start();
60  }
61 
62  $this->SecurityUtilities = get_package( 'security::security_utilities' , 'last' , __FILE__ );
63 
64  $this->SupportedDataTypes = get_package( 'security::supported_data_types' , 'last' , __FILE__ );
65  }
66  catch( Exception $e )
67  {
68  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
69  }
70  }
71 
94  function set_g( $Field , $Value )
95  {
96  try
97  {
98  if( isset( $_GET[ $Field ] ) === false )
99  {
100  $_GET[ $Field ] = $Value;
101  }
102  }
103  catch( Exception $e )
104  {
105  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
106  }
107  }
108 
131  function set_p( $Field , $Value )
132  {
133  try
134  {
135  if( isset( $_POST[ $Field ] ) === false )
136  {
137  $_POST[ $Field ] = $Value;
138  }
139  }
140  catch( Exception $e )
141  {
142  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
143  }
144  }
145 
168  function set_c( $Field , $Value )
169  {
170  try
171  {
172  if( isset( $_COOKIE[ $Field ] ) === false )
173  {
174  $_COOKIE[ $Field ] = $Value;
175  }
176  }
177  catch( Exception $e )
178  {
179  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
180  }
181  }
182 
205  function set_s( $Field , $Value )
206  {
207  try
208  {
209  if( isset( $_SESSION[ $Field ] ) === false )
210  {
211  $_SESSION[ $Field ] = $Value;
212  }
213  }
214  catch( Exception $e )
215  {
216  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
217  }
218  }
219 
242  function reset_s( $Field , $Value )
243  {
244  try
245  {
246  $_SESSION[ $Field ] = $Value;
247  }
248  catch( Exception $e )
249  {
250  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
251  }
252  }
253 
272  function unset_s( $Field )
273  {
274  try
275  {
276  unset( $_SESSION[ $Field ] );
277  }
278  catch( Exception $e )
279  {
280  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
281  }
282  }
283 
306  function reset_g( $Field , $Value )
307  {
308  try
309  {
310  $_SESSION[ $Field ] = $Value;
311  }
312  catch( Exception $e )
313  {
314  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
315  }
316  }
317 
336  function unset_g( $Field )
337  {
338  try
339  {
340  unset( $_GET[ $Field ] );
341  }
342  catch( Exception $e )
343  {
344  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
345  }
346  }
347 
374  function reset_c( $Field , $Value , $Expire = 0 )
375  {
376  try
377  {
378  setcookie( $Field , $Value , $Expire === 0 ? 0 : time() + $Expire );
379  $_COOKIE[ $Field ] = $Value;
380  }
381  catch( Exception $e )
382  {
383  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
384  }
385  }
386 
405  function unset_c( $Field )
406  {
407  try
408  {
409  unset( $_COOKIE[ $Field ] );
410  }
411  catch( Exception $e )
412  {
413  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
414  }
415  }
416 
439  function reset_p( $Field , $Value )
440  {
441  try
442  {
443  $_POST[ $Field ] = $Value;
444  }
445  catch( Exception $e )
446  {
447  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
448  }
449  }
450 
469  function unset_p( $Field )
470  {
471  try
472  {
473  unset( $_POST[ $Field ] );
474  }
475  catch( Exception $e )
476  {
477  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
478  }
479  }
480 
511  function get_g( $Field , $Type = 'set' , $Default = '_throw_exception' )
512  {
513  try
514  {
515  return( $this->SecurityUtilities->get_value( $_GET , $Field , $Type , $Default ) );
516  }
517  catch( Exception $e )
518  {
519  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
520  }
521  }
522 
553  function get_p( $Field , $Type = 'set' , $Default = '_throw_exception' )
554  {
555  try
556  {
557  return( $this->SecurityUtilities->get_value( $_POST , $Field , $Type , $Default ) );
558  }
559  catch( Exception $e )
560  {
561  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
562  }
563  }
564 
595  function get_s( $Field , $Type = 'set' , $Default = '_throw_exception' )
596  {
597  try
598  {
599  return( $this->SecurityUtilities->get_value( $_SESSION , $Field , $Type , $Default ) );
600  }
601  catch( Exception $e )
602  {
603  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
604  }
605  }
606 
637  function get_srv( $Field , $Type = 'set' , $Default = '_throw_exception' )
638  {
639  try
640  {
641  return( $this->SecurityUtilities->get_value( $_SERVER , $Field , $Type , $Default ) );
642  }
643  catch( Exception $e )
644  {
645  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
646  }
647  }
648 
679  function get_c( $Field , $Type = 'set' , $Default = '_throw_exception' )
680  {
681  try
682  {
683  return( $this->SecurityUtilities->get_value( $_COOKIE , $Field , $Type , $Default ) );
684  }
685  catch( Exception $e )
686  {
687  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
688  }
689  }
690 
721  function get_gp( $Field , $Type = 'set' , $DefaultValue = '_throw_exception' )
722  {
723  try
724  {
725  return( $this->SecurityUtilities->get_global( $Field , $Type , GET | POST , $DefaultValue ) );
726  }
727  catch( Exception $e )
728  {
729  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
730  }
731  }
732 
759  function get( $Data , $Type )
760  {
761  try
762  {
763  if( is_array( $Data ) || is_object( $Data ) )
764  {
765  return( $this->SupportedDataTypes->dispatch_complex_data( $Data , $Type ) );
766  }
767 
768  return( $this->SupportedDataTypes->compile_data( $Data , $Type ) );
769  }
770  catch( Exception $e )
771  {
772  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
773  }
774  }
775  }
776 
777 ?>