Adding user through PHP or any way

Dear All,

I have two site installed  1) Simple PHP based website 2) Elgg website . Both are on the same server

When a user gets created on first PHP based website , I want to connect to elgg database ( It is accesble ) and create an elgg user . I wrote a PHP code and trying to insert record into elgg_users_entity table .But not sure how to generate "password" ( based on what algorithm ) ?  Or is there any PHP file I can copy it to my first website and call elgg API to create an user ? Kindly let me if it is the first way ( through PHP code) what other tables I have to populate ( for default widgets and or there any other)

Thanks for your help

 

  • Did you check the readme file distributed with the plugin?

  • Thanks Cash for your response . yes I did check the readme file and configured the IP address . Moreover I am running both the applications ( elgg and other app) on the same server (Same virtual host).

    Regards

    Kiran

  • I think I resolved access error ( after talking to hosting team) , Now echo print_r($response) is returning '1' . But no record created at elgg end .

    Could somebody please help me ? Code is below and coreg settings I gave "username,password,name,email"

     

    <?php
    echo "My IP address ".$_SERVER['XML_RPC_IPs'];
    echo "\n";
    $params = array (
                        'username'    =>'testuser1',
                        'password'    =>'testpassword1',
                        'name'        =>'Test Name',
                        'email'        =>'testemail@abc.com',
                    );
    $XMLOptions     =       array(  'output_type' => 'xml',
                                    'verbosity' => 'pretty',
                                    'version' => 'xmlrpc',
                                    'debug' => 2);

    $request = xmlrpc_encode_request("coreg.register", $params, $XMLOptions);
    $context = stream_context_create(array('http' => array(
        'method' => "POST",
        'header' => "Content-Type: text/xml",
        'content' => $request
    )));
    $file = file_get_contents("http://mysite/xml-rpc.php", false, $context);
    $response = xmlrpc_decode($file);
    if (xmlrpc_is_fault($response)) {
        $response = $response['faultString'];
    }


    echo print_r($response);


    echo "<pre>\n".htmlentities($response)."\n</pre><hr>\n";
    ?>

  • Dear All

    I changed function function coregrpc_register(XMLRPCCall $data) to below for testing

      function coregrpc_register(XMLRPCCall $data)
        {

            $response = new XMLRPCSuccessResponse();
            $response->addString('<status> register1 </status>');
            return $response;

        }

     

    But still I see the response I am getting is print_r($response); is 1 .

    Could any body advise what I am doing wrong ?

    Regards

    Kiran

     

  • print_r only returns a string if you pass a second parameter of TRUE. Try using:

    print_r($response);

    or

    var_dump($response);

    instead of the echo print_r();

  • Thanks Cash four your response . I tried with below two

    print_r($response);  - Returned nothing
     var_dump($response); - Returned NULL

    Something goofy even for the below it returns the same

      function coregrpc_register(XMLRPCCall $data)
        {


                $response = new XMLRPCSuccessResponse();

                $response->addString('<status>Success</status><comment>test </comment>');
                return $response;

        }

     

    Regards

    Kiran

  • Something is going wrong with your upstream code then. You need to work backwards up the program flow until you find the problem (or start at the beginning and work forward).

  • True Cash , looks like some problem . I disabled the plugin and deleted it and run the test program and still got the same NULL :) .  I again copied the plugin to mod folder , enabled it and moved it to the first position to see and again the same problem . May be I will again cleanup my elgg1.7.3 and install it and try fist this plugin and see what it says

  •  

    THANKS A LOT Cash for helping me on this . I reinstalled elgg1.7.3 and only enabled this plugin . It is working like charm now . Before it worked the issues I faced

    1) Even though it is on the same server we have to add IP address to the server config file using XML-RPC-IPs

    2) Some hosting environments changing XML-RPC-IPs to always "XML_RPC_IPs" ( underscores ) always. So check the start.php code and change the '-'(Hyphen) to '_'( underscore)

    3)userid from the settings cannot be deleted , so I just renamed it to location and in testing program passed my location values

    That’s it , It worked just like that

    Once again thanks all for your help

    Regards

    Kiran