News:

Wondering if this will always be free?  See why free is better.

Main Menu

Registration from non-smf pages

Started by anwaraa, April 21, 2006, 10:46:41 AM

Previous topic - Next topic

anwaraa

Hi everyone.

I've just recently installed smf on my site. I wanted to make it such that a user can register/login/logout from a non-smf page ie from my main page. I've managed to achieve the login/logout by using ssi_login () and ssi_logout () functions. However I am battling to make the registration feature work as there are no functions for registration.

Please help.

Remaker

#1
Quote from: anwaraa on April 21, 2006, 10:46:41 AM
Hi everyone.

I've just recently installed smf on my site. I wanted to make it such that a user can register/login/logout from a non-smf page ie from my main page. I've managed to achieve the login/logout by using ssi_login () and ssi_logout () functions. However I am battling to make the registration feature work as there are no functions for registration.

Please help.

For the registration you should create your own registration function.
There is also a class with a function but I insert data directly into the mysql db.

For example:

<?
$newuser=array(strip_tags(strtolower(trim($_POST['username']))),strip_tags(trim(strtolower($_POST['password']))),strip_tags(strtolower(trim($_POST['mail']))),strip_tags(trim($_POST['name'])),trim($_POST['timestamp']),$_SERVER['REMOTE_ADDR'],$_POST['code'],$_SESSION['code']);
$mylink=@mysql_connect('localhost','','');
@mysql_select_db('db');
$maiil=mysql_num_rows(mysql_query('SELECT emailAddress FROM smf_members WHERE emailAddress="'.$newuser[2].'"'));
$usrr=mysql_num_rows(mysql_query('SELECT memberName FROM smf_members WHERE memberName="'.$newuser[0].'"'));
if ($maiil<>0 or $usrr<>0) { mysql_close($mylink); } else
{
if ($newuser[3]=='') $newuser[3]=$newuser[0];
$newuser[0]=mysql_real_escape_string($newuser[0]);
$newuser[1]=mysql_real_escape_string($newuser[1]);
$newuser[2]=mysql_real_escape_string($newuser[2]);
$newuser[3]=mysql_real_escape_string($newuser[3]);
$newuser[4]=mysql_real_escape_string($newuser[4]);
mysql_query('insert into smf_members (memberName,dateRegistered,realName,passwd,emailAddress,signature) values ("'.$newuser[0].'","'.date("U").'","'.$newuser[3].'","'.md5($newuser[1]).'","'.$newuser[2].'","A happy wallpaperbox user.")');
$usrc=mysql_fetch_row(mysql_query('SELECT value FROM smf_settings WHERE variable="totalMembers"'));
$mm=mysql_fetch_row(mysql_query('SELECT ID_MEMBER FROM smf_members WHERE memberName="'.$newuser[0].'"'));
mysql_query("UPDATE smf_settings SET value='".($usrc[0]+1)."' WHERE variable='totalMembers'");
mysql_query("UPDATE smf_settings SET value='".$newuser[3]."' WHERE variable='latestRealName'");
mysql_query("UPDATE smf_settings SET value='".$mm[0]."' WHERE variable='latestMember'");
mysql_close($mylink);
}

?>
Remaker - My blog

Leipe Po

that code really needs some more input validation, just a reminder....
There is only one thing more importend to me then coding:
My Girlfriend

Microsoft - "You've got questions.  We've got dancing paperclips."

anwaraa

Hi Remaker,

Thanks for the response and the code. But how do I use it?

Regards

Anwaraa

Remaker

You create a form that will send via post the required fields such as username,password, e-mail, name to this script. The script will than insert the new user into the smf database. ;)
Remaker - My blog

anwaraa

Thanks Remaker,

I'll give a try!

Regards

anwaraa

anwaraa

Hi Remaker,


Just tried it and it works like a charm - you are a star! Thanks for the help. Would you happen to know how to do the password reset reminder thingy from a non-smf page where the user gets taken back to the original yet non-smf page he was on before he asked for a password reminder?
(or am I asking for too much :-))

Regards

anwaraa

Remaker

Quote from: anwaraa on April 25, 2006, 11:13:44 AM
Hi Remaker,


Just tried it and it works like a charm - you are a star! Thanks for the help. Would you happen to know how to do the password reset reminder thingy from a non-smf page where the user gets taken back to the original yet non-smf page he was on before he asked for a password reminder?
(or am I asking for too much :-))

Regards

anwaraa

Hmm... don't know how to do that right now, but I will try checking that out and
if I will find a solution I will post it here..
Remaker - My blog

anwaraa

Thanks for all your help Remaker.

Regards
anwaraa

mama

this script look interesting Remaker, but I dont know how to put in this on my testform.

The problem for me is I don´t know what to write in the action (<form method="post" action="....">).

Could you, if you have time, make a small form so I could see how you did?

thanks in advanced.

Remaker

Quote from: mama on April 30, 2006, 05:06:53 AM
this script look interesting Remaker, but I dont know how to put in this on my testform.

The problem for me is I don´t know what to write in the action (<form method="post" action="....">).

Could you, if you have time, make a small form so I could see how you did?

thanks in advanced.

something like this:

<form action="TheregistrationPHPfilename.php" method="post" enctype="multipart/form-data" name="" id="">
username:
  <input name="username" type="text" id="username3">
  <BR />
password:
<input name="password" type="text" id="password3">
<BR />
e-mail:
<input name="mail" type="text" id="mail3">
<BR />
name:
<input name="name" type="text" id="name2">
<BR />
<input type="submit" name="Submit" value="Submit">
</form>


Don't forget to save the php file with a name and change the action url(TheregistrationPHPfilename.php)
Remaker - My blog

mama

#11
thx for the fast reply. =)

This is the thing I´ve done:

1. Copied that code you wrote about the database and save that as registeruser.php. This file I placed in folder smf/sources.
2. Copied your form code and saved as registeruser.html. Renamed the action link to: <form action="smf/Sources/registeruser.php" method="post" enctype="multipart/form-data" name="" id="">

3. But when I press submit from the html file I come to another page with alot pf errors.
Access denied for user, A link to the server could not be established, and so on.
I´m doing something wrong. :(

I have to mention that I´m testing this script in my computer using xampp for smf. All the files going through that and when its passed and looks ok I send it up top my real forum. Doing so with all the codes I bringing home. ;)

Vic

I was wanting to do something similar except I would like a user be able to start a new topic by entering the text into a form and not directly into SMF. I am looking to populate the SMF subject and body tables but the body would contain an address from the form that I create. Is it as simple as making the form and using the MySQL table as the data source? I guess what I'm asking is will SMF then see the topic and do what it normally does like send email's to the subscribers of the thread.

Remaker

Quote from: mama on April 30, 2006, 06:40:28 AM
thx for the fast reply. =)

This is the thing I´ve done:

1. Copied that code you wrote about the database and save that as registeruser.php. This file I placed in folder smf/sources.
2. Copied your form code and saved as registeruser.html. Renamed the action link to: <form action="smf/Sources/registeruser.php" method="post" enctype="multipart/form-data" name="" id="">

3. But when I press submit from the html file I come to another page with alot pf errors.
Access denied for user, A link to the server could not be established, and so on.
I´m doing something wrong. :(

I have to mention that I´m testing this script in my computer using xampp for smf. All the files going through that and when its passed and looks ok I send it up top my real forum. Doing so with all the codes I bringing home. ;)

you have to change this : $mylink=@mysql_connect('localhost','',''); from the php codeto this $mylink=@mysql_connect('localhost','YOUR DB USERNAME','YOUR DB PASSWORD');
and also @mysql_select_db('db'); to @mysql_select_db('YOUR DATABASE NAME HERE');

or you could include the settings.php file and change the variables name.
I will come back with details , if more required, later, I have to take a bath now :)
Remaker - My blog

mama

=), thx.

Now the errors is gone and now three errors came up:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ..forum\Sources\registeruser.php on line 13

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ...forum\Sources\registeruser.php on line 14

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in ...forum\Sources\registeruser.php on line 24

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in ...forum\Sources\registeruser.php on line 25


No stress to answer this thread. Take the bath you deserv, my questions make ppl sweat. :P


To bad that I don´t have alot of knowledge of php, but I hope it will come up someday.

Remaker

Quote from: Vic on April 30, 2006, 06:45:34 AM
I guess what I'm asking is will SMF then see the topic and do what it normally does like send email's to the subscribers of the thread.

SMF will not recognize the new topic so easy. You will have to insert alot of data, and update the database.
You better use the SMF's sub-classes...
Remaker - My blog

Remaker

Quote from: mama on April 30, 2006, 07:58:59 AM
=), thx.

Now the errors is gone and now three errors came up:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ..forum\Sources\registeruser.php on line 13

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ...forum\Sources\registeruser.php on line 14

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in ...forum\Sources\registeruser.php on line 24

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in ...forum\Sources\registeruser.php on line 25


No stress to answer this thread. Take the bath you deserv, my questions make ppl sweat. :P


To bad that I don´t have alot of knowledge of php, but I hope it will come up someday.


What version of SMF are you using? I made this on 1.1 RC2 .
Remaker - My blog

mama

I have smf 1.1 rc2.

When I tried this at my computer, using xampp as server, I get this error. But if I test it with my real forum I come to a empty registeruser.php site. Nothing happened. And that forum is 1.1 rc2 too.

Remaker

Quote from: mama on May 01, 2006, 06:29:37 AM
I have smf 1.1 rc2.

When I tried this at my computer, using xampp as server, I get this error. But if I test it with my real forum I come to a empty registeruser.php site. Nothing happened. And that forum is 1.1 rc2 too.


Well actually , the result should be a blank web page. ;) Try checking if the user is created...
strange...
Remaker - My blog

mama

Don´t see the user in latest user.
And when I press members button I get this error:

Parse error: syntax error, unexpected T_DOUBLE_ARROW in ......./forum/Sources/Memberlist.php on line 315

Advertisement: