PHP XML PARSER class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
# +----------------------------------------------------------------------+
# | PHP version 4.3.10
# +----------------------------------------------------------------------+
# | Copyright (c) 2001-2005 Web-Media.Ru
# +----------------------------------------------------------------------+
# | Authors: Original Author Andreas Sokov, http://j8.spb.ru
# +----------------------------------------------------------------------+
#
#
class xml  {
    #
   var $parser ;
    var $STRUCT_VALUE   = array() ;
    var $STRUCT_INDEX   = array() ;

    # +-----------------------------------------------------------------------+
   # |
   # +-----------------------------------------------------------------------+
   function xml()
    {
       $this->parser = xml_parser_create();

        xml_set_object($this->parser, $this);
        #
       #xml_set_element_handler($this->parser, "tag_open", "tag_close");
       #xml_set_character_data_handler($this->parser, "cdata");
       #
       xml_parser_set_option($this->parser,  XML_OPTION_CASE_FOLDING,    0 );
        xml_parser_set_option($this->parser,  XML_OPTION_SKIP_WHITE,      1 );
        #
       return true ;
    }

    # +-----------------------------------------------------------------------+
   # |
   # +-----------------------------------------------------------------------+
   function parse_into_struct( $data )
    {
        return xml_parse_into_struct($this->parser,  $data, $this->STRUCT_VALUE, $this->STRUCT_INDEX ) ;
    }

    # +-----------------------------------------------------------------------+
   # |
   # +-----------------------------------------------------------------------+
   function parser_free()
    {
        return xml_parser_free( $this->parser ) ;
    }

    # +-----------------------------------------------------------------------+
   # |
   # +-----------------------------------------------------------------------+
   function get_code_value( $tag )
    {
        #
       if ( isSet($this->STRUCT_INDEX[$tag]) ) {
            #
           $TAG_ = $this->STRUCT_INDEX[$tag] ;
            if ( sizeOf($TAG_)>1 ) {
                # open & close tags present
               $value_index = $TAG_[0] ;

            }else{
                # all data into one tag present
               # type == complete
               $value_index = $TAG_[0] ;
                #
               # get value for OPEN or COMPLETE tag
               return $this->STRUCT_VALUE[ $value_index ] ;
            }

        }else{
            return false ;
        }
    }


    # +-----------------------------------------------------------------------+
   # |
   # +-----------------------------------------------------------------------+
   function tag_open($parser, $tag, $attributes)
    {
       var_dump($parser, $tag, $attributes);
    }

    # +-----------------------------------------------------------------------+
   # |
   # +-----------------------------------------------------------------------+
   function cdata($parser, $cdata)
    {
       var_dump($parser, $cdata);
    }

    # +-----------------------------------------------------------------------+
   # |
   # +-----------------------------------------------------------------------+
   function tag_close($parser, $tag)
    {
       var_dump($parser, $tag);
    }




}
# +-----------------------------------------------------------------------+
# | end of class xml
# +-----------------------------------------------------------------------+
?>

nginx+apache+geoip HOWTO use REMOTE_ADDR

I want use REMOTE_ADDR in binding NGINX+APACHE, thank very much Andrey Chernomyrdin, for it we should use a few nginx directives + mod_rpaf for APACHE.

1. For DEBIAN (Ubuntu)

apt-get update
apt-get install geoip-bin
apt-get install libapache2-mod-geoip
apt-get install libapache2-mod-rpaf

2. Open nginx host config file and add into it following :

proxy_set_header        Host            $host;
proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

3. A litle miracle which help me with GEOIP :

cd /etc/apache2/mods-enabled/

and rename symlink rpaf.conf & rpaf.load to

000.rpaf.conf
000.rpaf.load