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.

Advertisement: