HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


ocf_make_member

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#36304 (In Topic #8177)
Avatar

Community saint

php NEWBIE tries [unsuccessfully] to use ocf_make_member API.

Hello!  I have tried to write my very first PHP script that create users in the ocPortal database utilizing the ocf_make_member function (included in sources/ocf_members.php) and am getting nowhere. bleh. Well, I did manage to figure out how to pull the user info I currently have from a cvs file but when I call the ocf_make_member function the script just stops. No message. Nothing. Below is a copy of the script and I am hoping someone - anyone - out there might show me the way (to do this correctly) because I definitely don't want to manually input nearly a thousand accounts.

Thanks in advance!!

~Scot

Here's what I have so far:


Code

<?php
  include('sources/ocf_members.php');
  $handle = fopen("members.csv", "r");
  while (($data = fgetcsv($handle, 100, ",")) !== FALSE) {
    $username = $data[0];
    $password = $data[1];
    $email_address = $data[2];
    echo "username = $username<br>\n";
    echo "password = $password<br>\n";
    echo "email = $email_address<br>\n";
    $member_id = ocf_make_member($username,$password,$email_address,NULL,NULL,NULL,NULL,NULL,0,NULL,1,time(),time(),'','','',0,1,0,'','','',1,0,1,NULL,1,'',NULL,'',true,'','');
    echo "$member_id\n";
    echo "<br><br>\n";
}
fclose($handle);
?>
 
Back to the top
 
Posted
Rating:
#36306
Avatar

ocPortal has a lot of start up code that needs to run before anything else, so it's not as simple as just requiring the file that contains the function.
The easiest thing to do is to remove the first include line, and put the lines of PHP code into the only function in data_custom/execute_temp.php. Then call up that script by URL.
That script's designed for running temporary code into an initialised ocPortal environemnt.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#36344
Avatar

Community saint

rats

Fatal error: Call to undefined function ocf_make_members() in /home/xxxxxx/dev.xxxxxx.com/html/data_custom/execute_temp.ph
p
on line 67


Last edit: by scotpower
Back to the top
 
Posted
Rating:
#37323
Avatar

Community saint

Working now...

What I was missing was to set pass the groups and customs_fileds in as arrays.  We're all good now… Thanks!

Code

function execute_temp() {

    $groups = Array('Regular');
    $custom_fields = Array('1'=>'');
 
    require_code('ocf_members_action');
    $handle = fopen("data_custom/members.csv", "r");
 
    while (($data = fgetcsv($handle, 100, ",")) !== FALSE) {

        $username = $data[0];
        $password = $data[1];
        $email_address = $data[2];

        echo "username = $username<br>\n";
        echo "password = $password<br>\n";
        echo "email = $email_address<br>\n";

        $memberid = ocf_make_member($username,$password,$email_address,$groups,NULL,NULL,NULL,$custom_fields,0,NULL,1,time(),time(),'','','',0,1,0,'','','',1,0,1,NULL,1,'',NULL,'',true,'','');

        echo "New member id = $memberid\n";
        echo "<br><br>\n";
    }
    fclose($handle);
}

Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: