News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

How am I supposed to grab user's personal information (email & username) ?

Started by Aktoraman, June 08, 2010, 03:43:11 AM

Previous topic - Next topic

Aktoraman

Hello to everyone.
I want to make an application inside SMF 2.0 RC3 with some benefits I get from SimplePortal 2.3.2.
This application is a button that every time a registered member clicks on it, it will generate an 8-digit code (different for each member) that will be send to the member via email and registered in certain column, i will create, inside the smf_members MySQL database table.
The problem that I have is,
When a registered member clicks on that button, how am I going to grab his personal information like email & username?
In a simple way : "How am I supposed to know which is the member that clicks on my button?"
Thanks in advance.


Aktoraman

Quote from: flapjack on June 08, 2010, 06:59:39 AM
$context['user']['name']
$context['user']['email']
Thank you very much!
You mean that if i use this context variable in my php form, i will be able to grab the user name and the user mail, of the person who clicks on my button?

CapadY

Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Aktoraman

Thank you very much for your support, i will try fix it.....and if it works i will mark it up as solved

flapjack

no problem, remember to register it as global variable if it won't work straight away

Phoestre

Quote from: flapjack on June 08, 2010, 01:20:33 PM
no problem, remember to register it as global variable if it won't work straight away

Wouldn't it be a security issue?

SMF 2.0RC3 + SimplePortal
Custom Theme + Latin5 Turkish
Ubuntu Lucid

Aktoraman

Hello again... 
Unfortunately...i didn't make it...
Is there any sample code to grab & use username and email , from members,
with these:

$context['user']['name']
$context['user']['email']


to use it as an example?
Thank you very much!

flapjack

grab how, when, where and what?

what I gave you is the code which gives you both, name and email, for the current member

Aktoraman

Quote from: flapjack on June 10, 2010, 03:33:42 PM
grab how, when, where and what?

what I gave you is the code which gives you both, name and email, for the current member
Ok my mistake.
I would like to see an example with this code in action.
Can you post something with this code , just to see how it works...?
Thank you.

flapjack


global $context;
echo 'You are logged in as: ', $context['user']['name']';
echo 'Your email is: ', $context['user']['email'];

Aktoraman

Quote from: flapjack on June 10, 2010, 07:29:36 PM

global $context;
echo 'You are logged in as: ', $context['user']['name']';
echo 'Your email is: ', $context['user']['email'];

Sorry for asking help again, but can you please take a look at this code and tell me if its gonna work, or not?
before i start to modify my smf_members table and make any huge mistake....  :)

<?php
global $context;

$_name $context['user']['name'];
$_email $context['user']['email'];

$pass=getPassword();

$headers 'From: [email protected]'."\r\n";
$headers .= 'MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8';

$to$_email
$subject="Welcome $_name"
$message="<p style='color:#000000'>Your game code of <b><span style='color:#FF0000; font-size:16px;'>MySMFforum</span></b> is <b><span style='color:#0000CC; font-size:16px;'>$pass</span></b></p>"

function 
getPassword()
{
$s='abcdefghijklmnopqrstuvwxyz0123456789';
$temp='';
for(
$i=0$i<8$i++) 

$r=rand(035); 
$temp .= substr ($s$r1); 

return 
$temp


$link mysql_connect('localhost''database_user''database_pass');
if (!
$link
{
    die(
'Could not connect: ' mysql_error());
}

$db_selected mysql_select_db('mydb'$link);
if (!
$db_selected)
{
    die (
'Can\'t use users: ' mysql_error());
}

$SQL="INSERT INTO `mydb`.`smf_members` (`pass`) VALUES ('$pass')";
mysql_query($SQL);

mysql_close($link);

$m=mail($to$subject$message);

if(
$m)
{
echo("Your code received");
}

else
{
echo("no");
}

?>


thank you!

CapadY

Id don't know what you are trying to do but it look likes you are inserting a record in the member database with only a password in it and the pasword is not protected.

Why not using SSI to login ?

It only need 2 rows of code.
same for logout and welcome message, when you already have the login included they wil need only one row of code.
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Aktoraman

Quote from: capady on June 12, 2010, 04:36:10 AM
Id don't know what you are trying to do but it look likes you are inserting a record in the member database with only a password in it and the pasword is not protected.

Why not using SSI to login ?

It only need 2 rows of code.
same for logout and welcome message, when you already have the login included they wil need only one row of code.
I just want to make a button and every member that clicks on it, the button will generate a code, send it to the member's email and register it in the smf_members column that iam trying to make.
So iam trying to fix a code with

$context['user']['name'];
$context['user']['email'];

And i was asking for someone to take a look at my code if its right or not...?
Or maybe i should change board and repost my query to
Scripting Help or at Help Wanted ???
What do you suggest ?

CapadY

I didn't test it but it looks good, except for the query to store the code.

Before storing any code in the database you have to expand the member table with a column, I think with a default value '' (empty string) . In this column the game code should be stored. Expanding the member table should be done wit PHPMyAdmin and have to ben done only once.

After that you don't use an insert query but an update query.

I havn't check it but it should be something like this:

Update table 'fieldname' as 'fieldvalue' where member_id = $context['user']['id']

As long as the value of the new field is an empty string there is no code provided yet. Is it another value then empty string you can check the code.
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Aktoraman

Quote from: capady on June 14, 2010, 10:39:29 AM
I didn't test it but it looks good, except for the query to store the code.

Before storing any code in the database you have to expand the member table with a column, I think with a default value '' (empty string) . In this column the game code should be stored. Expanding the member table should be done wit PHPMyAdmin and have to ben done only once.

After that you don't use an insert query but an update query.

I havn't check it but it should be something like this:

Update table 'fieldname' as 'fieldvalue' where member_id = $context['user']['id']

As long as the value of the new field is an empty string there is no code provided yet. Is it another value then empty string you can check the code.
Thank you very very much i will try it out ....
If it doesnt work would you mind to pm you and try it together (paid) ?

CapadY

Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

CapadY

The next code is tested and should work:


<?php

global $user_info$smcFunc;

$_name $user_info['name'];
$_email $user_info['email'];

$pass=getPassword();

$headers 'From: [email protected]'."\r\n";
$headers .= 'MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8';

$to$_email
$subject="Welcome $_name"
$message="<p style='color:#000000'>Your game code of <b><span style='color:#FF0000; font-size:16px;'>MySMFforum</span></b> is <b><span style='color:#0000CC; font-size:16px;'>$pass</span></b></p>"

function 
getPassword()
{
$s='abcdefghijklmnopqrstuvwxyz0123456789';
$temp='';
for(
$i=0$i<8$i++) 

$r=rand(035); 
$temp .= substr ($s$r1); 

return 
$temp


function 
generate()
{
global 
$user_info$smcFunc;
global 
$to$message$subject;

    
$result $smcFunc['db_query']('''
        UPDATE {db_prefix}members
        SET pass = {string:pass}
        WHERE id_member = {int:cur_member}'
,
        array(
            
'cur_member' => $user_info['id'],
            
'pass' => getPassword(),
        )
    );

    
$m=mail($to$subject$message);

    if(
$m)
    {
       echo(
'<script language ="JavaScript">Alert(\'Email with code is send\')</script>');
    }
    else
    {
        echo(
'<script language = "JavaScript">Alert(\'Failed to send Email\')</script>');
    }
}


Function "generete" can be called from index.php functions.
Don't forget to make a field "pass" in the members table via PHPMyAdmin before using it.
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Aktoraman

Quote from: capady on June 15, 2010, 06:54:33 AM
The next code is tested and should work:


<?php

global $user_info$smcFunc;

$_name $user_info['name'];
$_email $user_info['email'];

$pass=getPassword();

$headers 'From: [email protected]'."\r\n";
$headers .= 'MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8';

$to$_email
$subject="Welcome $_name"
$message="<p style='color:#000000'>Your game code of <b><span style='color:#FF0000; font-size:16px;'>MySMFforum</span></b> is <b><span style='color:#0000CC; font-size:16px;'>$pass</span></b></p>"

function 
getPassword()
{
$s='abcdefghijklmnopqrstuvwxyz0123456789';
$temp='';
for(
$i=0$i<8$i++) 

$r=rand(035); 
$temp .= substr ($s$r1); 

return 
$temp


function 
generate()
{
global 
$user_info$smcFunc;
global 
$to$message$subject;

    
$result $smcFunc['db_query']('''
        UPDATE {db_prefix}members
        SET pass = {string:pass}
        WHERE id_member = {int:cur_member}'
,
        array(
            
'cur_member' => $user_info['id'],
            
'pass' => getPassword(),
        )
    );

    
$m=mail($to$subject$message);

    if(
$m)
    {
       echo(
'<script language ="JavaScript">Alert(\'Email with code is send\')<script>');
    }
    else
    {
        echo(
'<script language = "JavaScript">Alert(\'Failed to send Email\')<script>');
    }
}


Function "generete" can be called from index.php functions.
Don't forget to make a field "pass" in the members table via PHPMyAdmin before using it.
Thanx again very much my friend, you are perfect!
Sorry but what do you mean by "Function "generete" can be called from index.php functions." ??
And ofcourse i wont forget to create the new column in the members table.
But if i want to generate the code only to the members that they dont have one... and dont make new code for those who own one, i should use an "if statement"......... 
how...??

CapadY

Here with an if-statement. Tested as wel:


<?php

global $user_info$smcFunc;

$_name $user_info['name'];
$_email $user_info['email'];

$pass=getPassword();

$headers 'From: [email protected]'."\r\n";
$headers .= 'MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8';

$to$_email
$subject="Welcome $_name"
$message="<p style='color:#000000'>Your game code of <b><span style='color:#FF0000; font-size:16px;'>MySMFforum</span></b> is <b><span style='color:#0000CC; font-size:16px;'>$pass</span></b></p>"

function 
getPassword()
{
$s='abcdefghijklmnopqrstuvwxyz0123456789';
$temp='';
for(
$i=0$i<8$i++) 

$r=rand(035); 
$temp .= substr ($s$r1); 

return 
$temp


function 
generate()
{
global 
$user_info$smcFunc;
global 
$to$message$subject;


    
$result $smcFunc['db_query']('''
        SELECT pass FROM {db_prefix}members
        WHERE id_member = {int:cur_member}
        LIMIT 1'
,
        array(
            
'cur_member' => $user_info['id'],
        )
    );

    if (!
$resultdb_fatal_error();
    else  {
        
$row $smcFunc['db_fetch_row']($result);
        
$code $row[0];
    }
    
$smcFunc['db_free_result']($result);

    if (
$code == '')    {
        
$result $smcFunc['db_query']('''
            UPDATE {db_prefix}members
            SET pass = {string:pass}
            WHERE id_member = {int:cur_member}'
,
            array(
                
'cur_member' => $user_info['id'],
                
'pass' => getPassword(),
            )
        );

        
$m=mail($to$subject$message);

        if(
$m)
        {
            echo(
'<script language ="JavaScript">Alert(\'Email with code is send\')</script>');
        }
        else
        {
            echo(
'<script language = "JavaScript">Alert(\'Failed to send Email\')</script>');
        }
    }
    
redirectexit();
}
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Aktoraman

Quote from: capady on June 15, 2010, 09:03:16 AM
Here with an if-statement. Tested as wel:


<?php

global $user_info$smcFunc;

$_name $user_info['name'];
$_email $user_info['email'];

$pass=getPassword();

$headers 'From: [email protected]'."\r\n";
$headers .= 'MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8';

$to$_email
$subject="Welcome $_name"
$message="<p style='color:#000000'>Your game code of <b><span style='color:#FF0000; font-size:16px;'>MySMFforum</span></b> is <b><span style='color:#0000CC; font-size:16px;'>$pass</span></b></p>"

function 
getPassword()
{
$s='abcdefghijklmnopqrstuvwxyz0123456789';
$temp='';
for(
$i=0$i<8$i++) 

$r=rand(035); 
$temp .= substr ($s$r1); 

return 
$temp


function 
generate()
{
global 
$user_info$smcFunc;
global 
$to$message$subject;


    
$result $smcFunc['db_query']('''
        SELECT pass FROM {db_prefix}members
        WHERE id_member = {int:cur_member}
        LIMIT 1'
,
        array(
            
'cur_member' => $user_info['id'],
        )
    );

    if (!
$resultdb_fatal_error();
    else  {
        
$row $smcFunc['db_fetch_row']($result);
        
$code $row[0];
    }
    
$smcFunc['db_free_result']($result);

    if (
$code == '')    {
        
$result $smcFunc['db_query']('''
            UPDATE {db_prefix}members
            SET pass = {string:pass}
            WHERE id_member = {int:cur_member}'
,
            array(
                
'cur_member' => $user_info['id'],
                
'pass' => getPassword(),
            )
        );

        
$m=mail($to$subject$message);

        if(
$m)
        {
            echo(
'<script language ="JavaScript">Alert(\'Email with code is send\')<script>');
        }
        else
        {
            echo(
'<script language = "JavaScript">Alert(\'Failed to send Email\')<script>');
        }
    }
    
redirectexit();
}

You are unbelievable  thank you very much!

Aktoraman

Quote from: capady on June 15, 2010, 09:03:16 AM
Here with an if-statement. Tested as wel:

<?php

global $user_info$smcFunc;

$_name $user_info['name'];
$_email $user_info['email'];

$pass=getPassword();

$headers 'From: [email protected]'."\r\n";
$headers .= 'MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8';

$to$_email
$subject="Welcome $_name"
$message="<p style='color:#000000'>Your game code of <b><span style='color:#FF0000; font-size:16px;'>MySMFforum</span></b> is <b><span style='color:#0000CC; font-size:16px;'>$pass</span></b></p>"

function 
getPassword()
{
$s='abcdefghijklmnopqrstuvwxyz0123456789';
$temp='';
for(
$i=0$i<8$i++) 

$r=rand(035); 
$temp .= substr ($s$r1); 

return 
$temp


function 
generate()
{
global 
$user_info$smcFunc;
global 
$to$message$subject;


    
$result $smcFunc['db_query']('''
        SELECT pass FROM {db_prefix}members
        WHERE id_member = {int:cur_member}
        LIMIT 1'
,
        array(
            
'cur_member' => $user_info['id'],
        )
    );

    if (!
$resultdb_fatal_error();
    else  {
        
$row $smcFunc['db_fetch_row']($result);
        
$code $row[0];
    }
    
$smcFunc['db_free_result']($result);

    if (
$code == '')    {
        
$result $smcFunc['db_query']('''
            UPDATE {db_prefix}members
            SET pass = {string:pass}
            WHERE id_member = {int:cur_member}'
,
            array(
                
'cur_member' => $user_info['id'],
                
'pass' => getPassword(),
            )
        );

        
$m=mail($to$subject$message);

        if(
$m)
        {
            echo(
'<script language ="JavaScript">Alert(\'Email with code is send\')</script>');
        }
        else
        {
            echo(
'<script language = "JavaScript">Alert(\'Failed to send Email\')</script>');
        }
    }
    
redirectexit();
}

Iam so sorry to bother you again, i need some extra help here.
I try to create the button in the Pages of SimplePortal in html environment of Add Page (SimplePortal) like this :

<form method="get"  action="pass.php" >
<input type="button" value="get pass" onclick="generate()" />
</form>

As you see iam trying to call the pass.php form and execute the generate() function (as you made for me)
I have already create the pass field (PhpMyAdmin) in smf_members table
But unfortunately nothing happens.....
What iam doing wrong ?
Is the php form wrong?
Is the way iam calling it?
I should call the getPassword() function instead?
Is the Add Page of SimplePortal not appropriate for this kind of actions? :-[
Please help me!!!!! :'(

CapadY

This wil never gonna work.

HTML is a clientsite language.
function Generate is a PHP action, so it is a serverside action

The HTML page don't know anything about the function Generate() because it's not included anywehere. So, the function will never be executed.

Why not just adding a menubutton in the default menubar ? It's the most easiest way and if you want you can hide that button for guests and for members that already have a password.
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Aktoraman

Quote from: capady on June 17, 2010, 10:06:41 AM
This wil never gonna work.

HTML is a clientsite language.
function Generate is a PHP action, so it is a serverside action

The HTML page don't know anything about the function Generate() because it's not included anywehere. So, the function will never be executed.

Why not just adding a menubutton in the default menubar ? It's the most easiest way and if you want you can hide that button for guests and for members that already have a password.
Thanx for your answer!
Which mod i must use to add a new menu button and work this function for me?
Maybe with Custom Tab?
And how can i use it?

CapadY

when you attach your source/subs.php and root/index.php in your next post I'll fix it for you.
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Aktoraman

Quote from: capady on June 17, 2010, 04:26:14 PM
when you attach your source/subs.php and root/index.php in your next post I'll fix it for you.
Ok Done...
I have attached source/subs.php & root/index.php
If you want please markup with a note the things you are going to fix in those forms, so i may figure out what changes have took place in there.
Thank you again Mr. Capady.

CapadY

Sorry, my car is broken and for me that's more important than your site :)

I've added some code but didn't test it.
Also the button is shown when allready a code has been send. The button isn't showed for guests.

I can't add comment in the code because the changes are made in an array.

In index.php one line of code is added on line 329
In subs.php 7 lines of code are added from line 4272

When you want to change the text on the button just edit the text in subs.php line 4273. The new button will now show "New Button".

Don't forget to empty the forumcache after youve made the changes. Otherwise the new button is probably not shown.

Good Luck
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Aktoraman

Quote from: capady on June 18, 2010, 04:08:50 AM
Sorry, my car is broken and for me that's more important than your site :)

I've added some code but didn't test it.
Also the button is shown when allready a code has been send. The button isn't showed for guests.

I can't add comment in the code because the changes are made in an array.

In index.php one line of code is added on line 329
In subs.php 7 lines of code are added from line 4272

When you want to change the text on the button just edit the text in subs.php line 4273. The new button will now show "New Button".

Don't forget to empty the forumcache after youve made the changes. Otherwise the new button is probably not shown.

Good Luck
Thank you again....iam sorry about your car, good luck also to you...

Aktoraman

Quote from: capady on June 18, 2010, 04:08:50 AM
Sorry, my car is broken and for me that's more important than your site :)

I've added some code but didn't test it.
Also the button is shown when allready a code has been send. The button isn't showed for guests.

I can't add comment in the code because the changes are made in an array.

In index.php one line of code is added on line 329
In subs.php 7 lines of code are added from line 4272

When you want to change the text on the button just edit the text in subs.php line 4273. The new button will now show "New Button".

Don't forget to empty the forumcache after youve made the changes. Otherwise the new button is probably not shown.

Good Luck
So i have uploaded my pass.php & Subs.php in Source folder and the inde.php in root, then i empty the cache and the button was there!
When i clicked on it nothing changed in my pass filed inside smf_members table..... ???

CapadY

Only the field "Pass" in your own memberrecord should change. Before klicking the button the Pass field in your memberrecord should be empty. If not empty, nothing happens cause you have a code received then before.
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Aktoraman

Quote from: capady on June 18, 2010, 06:35:09 AM
Only the field "Pass" in your own memberrecord should change. Before klicking the button the Pass field in your memberrecord should be empty. If not empty, nothing happens cause you have a code received then before.
Ok DONE it worked just fine!
Thank you very much!
But... i just wanted a code to insert in this field, the code, without getting involved the SMF function. (can i do it without SMF function, just PHP code?)
Now, i think, its very hard for me to add some things in it .... :(
Anyway
THANK YOU Mr. CAPADY! Your AWESOME!

CapadY

Oh yes, it can be done, I think it's not to hard.

But I'm not gonna start over again, so good luck :)
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Advertisement: