News:

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

Main Menu

Call a custom function from anywhere on the forum

Started by MobileCS, April 20, 2017, 03:38:08 PM

Previous topic - Next topic

MobileCS

Which file would I need to place my custom function in so it can be called from anywhere on the forum? (2.0.13)

Illori

can you provide some details as to what exactly you are wanting to do?

MobileCS

I'm creating a cookie - and I want my function to "create it / checks if it exists" when any of the forum pages are loaded.

Shambles

Then you have no choice other than to declare the function within index.php.

Arantor

Better question: why does it need to be a cookie or go into a cookie given that this means every single request to and from the server - every JS file, every image etc. - will send the cookie too? Can't it go into $_SESSION ?

MobileCS

Quote from: Arantor on April 20, 2017, 07:22:34 PM
Better question: why does it need to be a cookie or go into a cookie .. Can't it go into $_SESSION ?

$_SESSION expires after 1440 seconds and I'm trying to track how many visitors visit my website/forum (combined) per day. I can just have the cookie expire at midnight, clear the database and start fresh at 12am each day. This is for a PHP project I am doing, I'm not trying to reinvent Google Analytics :)

Quotethis means every single request to and from the server - every JS file, every image etc. - will send the cookie too?

All static files are delivered via EdgeCast CDN - so the cookie is never attached.

Arantor

If that were true, the admin area would boot you out after 20 minutes as opposed to the actual hour it boots you out after.

Kindred

why do you need a cookie at all?


when a guest connects, record the IP - set your code to only record an IP which is not already existing in the list

there you go. done. No cookie needed, all code is server side.

(actually, SMF et all already do exactly this)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

MobileCS

IP address is not 100% accurate (due to shared IP's). Which is the method I'm using now and would like to change.

Now with that said, is the index.template.php file used for the main board, message and thread index pages? That's all I really care about tracking.


Arantor

index.template.php is used literally everywhere. It's the header + footer for the site.

richardwbb

I've learned to preferably not touch index.php [while I know it can be done].

This I have all the way at the end [really at the end].
log_smf_txt();

function log_smf_txt() {
echo 'Hello world';
?>


If my post in this topic looks ambigous to you, then I'm with General Stupidity and Murphy's law. In other words, trial and error, haha.
If my post in this topic looks ambiguous to you, then I'm with Murphy's law and General Stupidity. In other words, trial and error.

Advertisement: