Search

Hi guys,

As I'm such a noob with PHP seems like I need a little help. Here's the deal:

  1. I have a section with a list of IPs (from the users who "liked" a project);
  2. When a users enters a project page I'd like to check if his IP is already stored for that project (he already 'liked') and choose witch button to show.
  3. I'm using the following DS code (based on Nick Dunn's Tag List)

    <?php

    require_once(TOOLKIT . '/class.datasource.php');
    
    Class datasourceUser_IP extends Datasource{
    
        function about(){
            return array(
                    'name' => 'User IP',
                    'author' => array(
                        'name' => '',
                        'website' => '',
                        'email' => ''),
                    'version' => '1.0',
                    'release-date' => '');
        }
    
        function grab(&$param_pool){
    
            $IP = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]; 
    
            /*THE UNKNOWN*/
        }
    }
    

    ?>

  4. What I'm acctually trying to do is to general a XML with the user's IP in order to check with but I just can't imagine how to go from /THE UNKNOWN/ :D to a XML result.

Done!

It turns out to be very simple.

Here's the DS code: <?php

    require_once(TOOLKIT . '/class.datasource.php');

    Class datasourceUser_IP extends Datasource{

        function about(){
            return array(
                    'name' => 'User IP',
                    'author' => array(
                        'name' => 'Fabio Pittol',
                        'website' => 'http://zero27.com',
                        'email' => 'info@zero27.com'),
                    'version' => '1.0',
                    'release-date' => '2011-08-29T12:00:00+00:00');
        }

        function grab(&$param_pool){

            $getIP = $_SERVER['REMOTE_ADDR']; 
            $result = new XMLElement("user-ip");

            $ip_node = new XMLElement("ip", $getIP);
            $result->appendChild($ip_node);

            return $result;
        }
    }

?>

And the XML:

<user-ip>
     <ip>127.0.0.1</ip>
</user-ip>

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details