How to rewrite register_user to own site register page

Hi,

I have own site and I have install elgg in subdir elgg/

I have add to register_form.php page in my own site  part of code to add user to elgg DB with the same parameters username/password/eamil because I want to  register in one place and one time by users. OK I have search google, this group and I have find suggestion that how to add in my register.php part of code:

require_once(dirname(dirname(__FILE__)) . "/elgg/engine/start.php");
        global $CONFIG;

$guid = register_user($username, $password, $username, $email);

 

When I have do this in separate file for example reg.php only with this code all working fine but when I have put in my register_form.php don't work and in log  following messages:

------------------------------------

[Mon Aug 16 04:49:49 2010] [error] [client ] WARNING: 2010-08-16 04:49:49 (UTC): "mysql_real_escape_string(): Access denied for user 'www-data'@'localhost' (using password: NO)" in file /var/www/elgg/engine/lib/database.php (line 617)
[Mon Aug 16 04:49:49 2010] [error] [client ] WARNING: 2010-08-16 04:49:49 (UTC): "mysql_real_escape_string(): A link to the server could not be established" in file /var/www/elgg/engine/lib/database.php (line 617)
[Mon Aug 16 04:49:49 2010] [error] [client ] WARNING: 2010-08-16 04:49:49 (UTC): "mysql_real_escape_string(): Access denied for user 'www-data'@'localhost' (using password: NO)" in file /var/www/elgg/engine/lib/database.php (line 617)
[Mon Aug 16 04:49:49 2010] [error] [client ] WARNING: 2010-08-16 04:49:49 (UTC): "mysql_real_escape_string(): A link to the server could not be established" in file /var/www/elgg/engine/lib/database.php (line 617)
[Mon Aug 16 04:49:49 2010] [error] [client ] WARNING: 2010-08-16 04:49:49 (UTC): "mysql_connect(): Access denied for user 'www-data'@'localhost' (using password: NO)" in file /var/www/elgg/engine/lib/database.php (line 51)
[Mon Aug 16 04:49:49 2010] [error] [client ] WARNING: 2010-08-16 04:49:49 (UTC): "fopen(/sess_): failed to open stream: Permission denied" in file /var/www/elgg/engine/lib/sessions.php (line 688)
[Mon Aug 16 04:50:20 2010] [error] [client ] WARNING: 2010-08-16 04:50:20 (UTC): "Cannot use a scalar value as an array" in file /var/www/elgg/engine/lib/database.php (line 51), referer: http://localhost/reg_test.php
[Mon Aug 16 04:50:20 2010] [error] [client ] *** FATAL EXCEPTION *** : exception 'DatabaseException' with message 'Elgg couldn't connect to the database using the given credentials.' in /var/www/elgg/engine/lib/database.php:54\nStack trace:\n#0 /var/www/elgg/engine/lib/database.php(91): establish_db_link('readwrite')\n#1 /var/www/elgg/engine/lib/database.php(154): setup_db_connections()\n#2 /var/www/elgg/engine/lib/database.php(321): get_db_link('read')\n#3 /var/www/elgg/engine/lib/users.php(1026): get_data_row('SELECT e.* from...')\n#4 /var/www/elgg/engine/lib/users.php(1528): get_user_by_username('test')\n#5 /var/www/oc/relgg.php(175): register_user('test', '*****', 'test', 'test@world.com')\n#6 {main}, referer: http://localhost/reg_test.php
[Mon Aug 16 04:50:20 2010] [error] [client ] WARNING: 2010-08-16 04:50:20 (UTC): "Cannot use a scalar value as an array" in file /var/www/elgg/engine/lib/database.php (line 51), referer: http://localhost/reg_test.php
[Mon Aug 16 04:50:20 2010] [error] [client ] PHP Fatal error:  Exception thrown without a stack frame in Unknown on line 0, referer: http://localhost/reg_test.php
---------------------------

I don't know where is problem for this reason I will try write register_user function in my part of code to add user in DB elgg below but I am not sure is it all to do add user to DB ?:

$lastGUID=sqlValue("SELECT MAX(guid) guid from elgg_entities",0);
$guid=$lastGUID+1;
$salt=substr(md5(microtime() . rand()), 0, 8);
$pass=md5($password . $salt);
$action_time=microtime(true);


sql("INSERT INTO elgg_entities (guid ,type ,subtype ,owner_guid ,site_guid ,container_guid ,access_id ,time_created,time_updated,last_action,enabl
ed) VALUES ('&1','user','0','0','1','0','2','&2','&3','0','yes')",$guid,$action_time,$action_time);

sql("INSERT INTO `elgg_users_entity` (`guid`,`name`, `username`, `password`,`salt`, `email`) VALUES (
    '&1','&2','&3','&4','&5','&6')",$guid,$username,$username, $pass,$salt, $email);

 

Thanks for any help and suggestion

 

Regards

 

  • (1)   you cut paste lots of junk text from msword lolz

    (2)   your code is 99% the wrong way to add users into elgg ;-)

  • Add 1. Sorry for mistake.

    Add 2. Ok thanks for your feedback

    but any suggestion how to add user in elgg DB in own part of code ?

  • Last time I did this sort of thingy.. it took me 4 hours to load about 11,000 users onto Elgg... ;-)

  • I think that exist conflict between my  settings php in main site and call functions register_user. For this reason don't exist way use register_user() from elgg only I must rewrite part of code from user.php elgg in my code and put to DB ? But maybe someone knows the solution how to call register_user() in own pages outside elgg ?

  • Include the elgg engine in the php script you want to call register_user() from.

  • Yes I have on begining my php script

    require_once(dirname(dirname(__FILE__)) . "/elgg/engine/start.php");
            global $CONFIG;

    but when I have call register_user function is problem

    WARNING: 2010-08-16 10:14:06 (UTC): "mysql_real_escape_string(): Access denied for user 'www-data'@'localhost' (using password: NO)" in file /var/www/test/elgg/engine/lib/database.php (line 617)

    WARNING: 2010-08-16 10:14:06 (UTC): "fopen(/sess_): failed to open stream: Permission denied" in file /var/www/test/elgg/engine/lib/sessions.php (line 688)

    WARNING: 2010-08-16 10:14:28 (UTC): "Cannot use a scalar value as an array" in file /var/www/test/elgg/engine/lib/database.php (line 51), referer: http://localhost/reg_test.php
    [Mon Aug 16 10:14:28 2010] [error] [client 127.0.0.1] *** FATAL EXCEPTION *** : exception 'DatabaseException' with message 'Elgg couldn't connect to the database using the given credentials.' in /var/www/test/elgg/engine/lib/database.php:54\nStack trace:\n#0 /var/www/test/elgg/engine/lib/database.php(91): establish_db_link('readwrite')\n#1 /var/www/test/elgg/engine/lib/database.php(154): setup_db_connections()\n#2 /var/www/test/elgg/engine/lib/database.php(321): get_db_link('read')\n#3 /var/www/test/elgg/engine/lib/users.php(1026): get_data_row('SELECT e.* from...')\n#4 /var/www/test/elgg/engine/lib/users.php(1528): ...

     

     

  • I have add

    require_once(dirname(dirname(__FILE__)) . "/elgg/engine/settings.php");

    and remove problem

    WARNING: 2010-08-16 10:14:06 (UTC): "mysql_real_escape_string(): Access denied for user 'www-data'@'localhost' (using password: NO)" in file /var/www/test/elgg/engine/lib/database.php (line 617)

    WARNING: 2010-08-16 10:14:06 (UTC): "fopen(/sess_): failed to open stream: Permission denied" in file /var/www/test/elgg/engine/lib/sessions.php (line 688)

    but still problem

    WARNING: 2010-08-16 10:14:28 (UTC): "Cannot use a scalar value as an array" in file /var/www/test/elgg/engine/lib/database.php (line 51), referer: http://localhost/reg_test.php
    [Mon Aug 16 10:14:28 2010] [error] [client 127.0.0.1] *** FATAL EXCEPTION *** : exception 'DatabaseException' with message 'Elgg couldn't connect to the database using the given credentials.' in /var/www/test/elgg/engine/lib/database.php:54\nStack trace:\n#0 /var/www/test/elgg/engine/lib/database.php(91): establish_db_link('readwrite')\n#1 /var/www/test/elgg/engine/lib/database.php(154): setup_db_connections()\n#2 /var/www/test/elgg/engine/lib/database.php(321): get_db_link('read')\n#3 /var/www/test/elgg/engine/lib/users.php(1026): get_data_row('SELECT e.* from...')\n#4 /var/www/test/elgg/engine/lib/users.php(1528): ...

  • Is there a conflict on the global $CONFIG?

    I'd use Elgg's web services API to expose a method for adding a user rather than directly including the engine.

  • I don't know how to check if exist conflict on the global $CONFIG

    How to use Elgg's web service API to adding a user ? any example ?