1
luckylin
Hack help: Send a notification when a user login
  • 2006/7/20 15:22

  • luckylin

  • Just popping in

  • Posts: 35

  • Since: 2004/3/5 2


I have searched the forum but only seen "send a welcome PM to new user" that is close to but not what I want to. I want to have a notification whenever an registered user is logged in. To some this might be needless but it is a good way for me to catch up with my members without delay, as long as I don't really have huge users to flood my email.

I looked into the USER.php, find the lines -

Quote:


if ($op == 'login') {
include_once XOOPS_ROOT_PATH.'/include/checklogin.php';
}
exit();



add my code in-between as -


Quote:


if ($op == 'login') {
$email = "my_notifying@email.address" ;
$loginuser = $xoopsUser->getVar('uid') ;
if (isset($email)) {
mail( $email, "your subject for User Login",
"$loginuser has just logged in.",
"From: Webmaster <webmaster@mysite.com>" );
include_once XOOPS_ROOT_PATH.'/include/checklogin.php';
}

exit();




The email works. But I can't have the login username to be in place. I understand that the $loginuser should not be in the email body it won't trigger, but I can't find a way to work around, can anyone gives me a quick light of this?

Thanks in advanced.

...

2
Dave_L
Re: Hack help: Send a notification when a user login
  • 2006/7/20 15:36

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Quote:
But I can't have the login username to be in place. I understand that the $loginuser should not be in the email body it won't trigger, but I can't find a way to work around, can anyone gives me a quick light of this?


I don't understand what you're saying.

-----

But I think you're sending the email too early; the user's info hasn't been fetched from the database yet.

I would put the added code in include/checklogin.php, instead of in user.php.

If you only want to get the email after a successful login, you could send the email near the end, e.g. after:

$notification_handler->doLoginMaintenance($user->getVar('uid'));

3
luckylin
Re: Hack help: Send a notification when a user login
  • 2006/7/20 16:01

  • luckylin

  • Just popping in

  • Posts: 35

  • Since: 2004/3/5 2


Quote:

Dave_L wrote:

I don't understand what you're saying.

-----

But I think you're sending the email too early; the user's info hasn't been fetched from the database yet.

I would put the added code in include/checklogin.php, instead of in user.php.

If you only want to get the email after a successful login, you could send the email near the end, e.g. after:

$notification_handler->doLoginMaintenance($user->getVar('uid'));



Yup that is what exactly I am saying, the email did not show me the username as you descirbed it is sent too early. I will give it a try with the checklogin.php instead user.php, thanks!
...

4
luckylin
Re: Hack help: Send a notification when a user login
  • 2006/7/20 16:15

  • luckylin

  • Just popping in

  • Posts: 35

  • Since: 2004/3/5 2


Quote:


If you only want to get the email after a successful login, you could send the email near the end, e.g. after:

$notification_handler->doLoginMaintenance($user->getVar('uid'));


Update: yes it is perfectly working. I got the user name and ID in the email. Thanks for the heads-up!
...

5
JamesSAEP
Re: Hack help: Send a notification when a user login
  • 2006/7/28 22:01

  • JamesSAEP

  • Just can't stay away

  • Posts: 732

  • Since: 2005/2/28


Are you using 2.0.14? If so, what code did you put in the checklogin.php file? I tried your code form the thread and when I try to login, it has a blank page.

6
luckylin
Re: Hack help: Send a notification when a user login
  • 2006/8/17 1:44

  • luckylin

  • Just popping in

  • Posts: 35

  • Since: 2004/3/5 2


Quote:

JamesSAEP wrote:
Are you using 2.0.14? If so, what code did you put in the checklogin.php file? I tried your code form the thread and when I try to login, it has a blank page.


I am using 2.0.13 so I guess that should be the same... (?)

Followed the suggestion I only modified the checklogin.php,

find the latest portion and change to -


// Perform some maintenance of notification records
    
$notification_handler =& xoops_gethandler('notification');
    
$notification_handler->doLoginMaintenance($user->getVar('uid'));
    
$loginuserid $user->getVar('uid') ;
    
$userurl "http://www.yoursite.com/xoops/userinfo.php?uid=$loginuserid;
// by luckylin -- you MUST change the URL to your site 
    
if ($loginuserid != && $loginuserid != && $loginuserid != && $loginuserid != 100 && $loginuserid != 50) {
// by luckylin -- these are to opt out NO-NEED-TO-MONITOR users, you have to check the id number first
    
mail"admin1@list1.com, admin2@list2.com""User $uname Login Alert",
    
"User Login Notification:nn$uname (ID:$loginuserid) has just logged in. nn$userurlnn",
    
"From: Webmaster" ); 
    }
// by luckylin -- change your email, subject and emailbody 
    
redirect_header($url1sprintf(_US_LOGGINGU$user->getVar('uname')));
} else {


It's been working well for already a month. Good luck.
...

7
JamesSAEP
Re: Hack help: Send a notification when a user login
  • 2006/8/17 15:02

  • JamesSAEP

  • Just can't stay away

  • Posts: 732

  • Since: 2005/2/28


I made the changes to the checklogin.php file but I get a blank page when I try login. The code I put in the file is:

// Perform some maintenance of notification records
$notification_handler =& xoops_gethandler('notification');
$notification_handler->doLoginMaintenance($user->getVar('uid'));
$loginuserid $user->getVar('uid') ;
$userurl "http://www.mydonain.com/userinfo.php?uid=$loginuserid;
// by luckylin -- you MUST change the URL to your site
if ($loginuserid != && $loginuserid != && $loginuserid != && $loginuserid != 100 && $loginuserid != 50) {
// by luckylin -- these are to opt out NO-NEED-TO-MONITOR users, you have to check the id number first
mail"webmaster@mydomain.com""User $uname Login Alert",
"User Login Notification:nn$uname (ID:$loginuserid) has just logged in. nn$userurlnn",
"From: Webmaster" );
}
// by luckylin -- change your email, subject and emailbody
redirect_header($url1sprintf(_US_LOGGINGU$user->getVar('uname')));
} else {

    
redirect_header($url1sprintf(_US_LOGGINGU$user->getVar('uname')), false);
} else {
    
redirect_header(XOOPS_URL.'/user.php'5$xoopsAuth->getHtmlErrors());
}
exit();

?>


This is the only file I modified. Did I miss something?

8
luckylin
Re: Hack help: Send a notification when a user login
  • 2006/8/17 19:42

  • luckylin

  • Just popping in

  • Posts: 35

  • Since: 2004/3/5 2


Not sure if 2.0.13 and 2.0.14 matters.

Please try a very simple modification first - add a mail function:


in checklogin.php


$notification_handler->doLoginMaintenance($user->getVar('uid'));

mail("your.admin@email.com""User Login Notofication""TEST""From: Webmaster"); 

redirect_header($url1sprintf(_US_LOGGINGU$user->getVar('uname')));


Touch nothing but adding the mail line.

This SHOULD send you a simple test email whenever a user logged in. If you failed to get email, it might mean you need to tweak your mail settings..

Good luck!
...

9
JamesSAEP
Re: Hack help: Send a notification when a user login
  • 2006/8/17 20:11

  • JamesSAEP

  • Just can't stay away

  • Posts: 732

  • Since: 2005/2/28


Ok, adding this one line worked:

mail("webmaster@mydomain.com""User Login Notofication""TEST""From: Webmaster");


So, I added the following to the file:
$loginuserid $user->getVar('uid') ;
    
$userurl "http://www.domain.com/userinfo.php?uid=$loginuserid;
    if (
$loginuserid != && $loginuserid != && $loginuserid != && $loginuserid != 100 && $loginuserid != 50)     {
    
mail"webmaster@domain.com""User $uname Login Alert",
    
"User Login Notification:nn$uname (ID:$loginuserid) has just logged in. nn$userurlnn",
    
"From: Webmaster" );
}

redirect_header($url1sprintf(_US_LOGGINGU$user->getVar('uname')));


and I can login, but no email is received.

I put this code between the following to lines:
$notification_handler->doLoginMaintenance($user->getVar('uid'));
ADDED CODE HERE

} else {
redirect_header(XOOPS_URL.'/user.php', 5, $xoopsAuth->getHtmlErrors());

10
luckylin
Re: Hack help: Send a notification when a user login
  • 2006/8/18 4:59

  • luckylin

  • Just popping in

  • Posts: 35

  • Since: 2004/3/5 2


The position is correct, so I now am thinking it might be a VERY simple error you've made - the code somehow break into lines which will stop working in php, please carefully check the code see if there is any "hard break line" in between code, it's my guess now.


// Perform some maintenance of notification records
    
$notification_handler =& xoops_gethandler('notification');
    
$notification_handler->doLoginMaintenance($user->getVar('uid'));
    
$loginuserid $user->getVar('uid') ;
    
$userurl "http://www.yoursite.com/xoops/userinfo.php?uid=$loginuserid;
// by luckylin -- you MUST change the URL to your site 
    
if ($loginuserid != && $loginuserid != && $loginuserid != && $loginuserid != 100 && $loginuserid != 50) {
// by luckylin -- these are to opt out NO-NEED-TO-MONITOR users, you have to check the id number first
    
mail"admin1@list1.com, admin2@list2.com""User $uname Login Alert",
    
"User Login Notification:nn$uname (ID:$loginuserid) has just logged in. nn$userurlnn",
    
"From: Webmaster" ); 
    }
// by luckylin -- change your email, subject and emailbody 
    
redirect_header($url1sprintf(_US_LOGGINGU$user->getVar('uname')));
} else {
...

Login

Who's Online

166 user(s) are online (109 user(s) are browsing Support Forums)


Members: 1


Guests: 165


mailsdaddy,

more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits