Skip to Content Skip to Menu

🌲 Merry Christmas! Great savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2024!

Triggering php file after login

  • bizguy
  • bizguy
  • OFFLINE
  • Posts: 199
  • Thanks: 32
  • Karma: 5
9 years 9 months ago - 9 years 9 months ago #261355 by bizguy
Triggering php file after login was created by bizguy
I want to execute a php file when a user logs in.
I setup a test file in the tmp directory ...

hello file contents
Code:
<?php echo "<h1>Hello [firstname] [lastname] </h1>"; ?>

Then within Auto Actions (After User Login) > Code > PHP (eval) / echo
Code:
<?php global $_CB_framework; require_once( $_CB_framework->getCfg( 'absolute_path' ). '/tmp/hello.php' ); ?>

Using the "Click to Execute" link in Auto Actions takes me to a screen with a blank contents area.

Am I missing something as I expected to see the message
Last edit: 9 years 9 months ago by bizguy. Reason: code corrections

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48630
  • Thanks: 8307
  • Karma: 1446
9 years 9 months ago #261416 by krileon
Replied by krileon on topic Triggering php file after login
There's a redirect directly after logout so there is no output, which means you can't echo anything on that trigger. In addition to that substitutions will not process on the included file. I'm also unsure why you're using an include for a simple echo though; just add the echo directly to the code action.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • bizguy
  • bizguy
  • OFFLINE
  • Posts: 199
  • Thanks: 32
  • Karma: 5
9 years 9 months ago #261468 by bizguy
Replied by bizguy on topic Triggering php file after login
Hi Kyle:

Thank you for the reply and clarification.
I wasn't sure if my coding was correct to reach my intended php file, so was simply using the hello file to test.
The actual file I am working on does a number of things and doesn't need to echo anything, so as long as my Auto Actions coding is correct I should be ok.

Will $user->id be available?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48630
  • Thanks: 8307
  • Karma: 1446
9 years 9 months ago #261493 by krileon
Replied by krileon on topic Triggering php file after login

Will $user->id be available?

If using eval method then probably. Otherwise create_function doesn't have access to variables outside its scope (so access to nothing). The eval method you maybe able to access $user object already present. You can also access the trigger with $trigger and the code params with $row.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • bizguy
  • bizguy
  • OFFLINE
  • Posts: 199
  • Thanks: 32
  • Karma: 5
9 years 8 months ago - 9 years 8 months ago #261618 by bizguy
Replied by bizguy on topic Triggering php file after login
Thanks Kyle.

I have a problem with Auto Actions performing. I have 5 Actions setup to perform separately after a new members first login to configure their account. The first 4 work properly every time. The 5th is the PHP eval Action and includes the following code in the action:
Code:
<?php global $_CB_framework; require_once( $_CB_framework->getCfg( 'absolute_path' ). '/includes/points.php' ); ?>
I have attached the file being called as well. I use Flexi Custom Code module to easily test PHP code I build and with the require_once code in the module, the script executes correctly. With the code in Auto Actions, the first 4 complete correctly, but this 5th one doesn't. The actions are as follows:
  1. Update one user field with info from another - Field
  2. Setup a connection between the member and another - Connection
  3. store some data in an external db - Query
  4. update some data in the users file - Query
  5. run the attached script - Code

Your help is appreciated.


File Attachment:

File Name: points.txt
File Size:7 KB

File is a PHP file.
Attachments:
Last edit: 9 years 8 months ago by bizguy.

Please Log in or Create an account to join the conversation.

  • bizguy
  • bizguy
  • OFFLINE
  • Posts: 199
  • Thanks: 32
  • Karma: 5
9 years 8 months ago #261639 by bizguy
Replied by bizguy on topic Triggering php file after login
I think possibly my problem is that $user->id isn't available in the PHP eval script. It is when I use Flexi Custom Code, but not in this Auto Action.
I tried passing the current user id in the URL as:
Code:
require_once( $_CB_framework->getCfg( 'absolute_path' ). '/includes/hello.php?currentUserRefCode='.$user->id);
But this only resulted in an error.
Any suggestions on how I can pass along the user or get the user once in my script?
Thanks.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum