admin管理员组文章数量:1425675
On a business listing in a directory I have a button which will lead to a custom plugin.
The custom plugin needs to know the userid of the user (registered user) who clicked the button to get here, plus the business id of the page it came from.
How do I track that info in the plugin?
Thanks.
On a business listing in a directory I have a button which will lead to a custom plugin.
The custom plugin needs to know the userid of the user (registered user) who clicked the button to get here, plus the business id of the page it came from.
How do I track that info in the plugin?
Thanks.
Share Improve this question asked May 28, 2019 at 20:52 Shaun21ukShaun21uk 311 silver badge8 bronze badges2 Answers
Reset to default 0Although you can put parameters on a URL link, be really careful about the parameters you use.
For example, the other answer suggest using a parameter like this:
https://www.example/somepage/?userid=12
Using the user ID number isn't really safe. What is to stop an unscrupulous person to use your link, but another user ID number? Bad things might (or might not) happen, depending on how you use that value. (Not to mention the possible exposure of user IDs....what if the nefarious person used a user ID of '1' - which is usually the 'admin' user?)
Better to use a session variable to keep track of someone accessing your site. Or, a cookie (although there are those pesky GDPR guys to worry about).
But I am not a fan of using query strings that contains possible personal information.
Added
As for implementation (or even the code), I leave that to the OP. But I would
- create a GUID value unique to that user. Do it after a login, and store it as a session
- create the other variables you need
- put the GUID together with the other variables. If you want, encode them a bit. Maybe an array into JSON? Whatever works
- add that value to the URL
- give the URL to the visitor
When the user click on the URL
- check the GUID value in your session variable to ensure it matches with the GUID in the URL
- if OK, extract the other values as needed
- if not OK, put up a warning/error message to the visitor asking them to log in and try again
The GUID is a value that can't be (easily) figured out. Make it 40 chars long. Lots of GUID generator functions available on the googles/bings/ducks.
Storing it as a session variable means it will be available to the user as long as they stay on your site (until the session variable expires).
If you need to further obfuscate the other variables in the query string (that are added to the GUID variable), then encode/decode as needed.
Code to do all of this is on the googles/bings/ducks. You should be able to find something that you can modify for your specific needs.
The above is just a quick idea. You might think of enhancements that are useful to your situation.
Not really sure, but you can pass a variable on that link, and load the desired page with the variable in URL.
<?php $user_id = get_current_user_id(); ?>
<a href="/my-plugin-url<?php echo $user_id; ?>">View/Download plugin</a>
This will load /my-plugin-url page, with the user_id to track
本文标签: phpHow do I track which user clicked my button
版权声明:本文标题:php - How do I track which user clicked my button? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745454926a2659057.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论