Advertisement:

Author Topic: Call a custom function from anywhere on the forum  (Read 2717 times)

Offline MobileCS

  • Jr. Member
  • **
  • Posts: 117
Call a custom function from anywhere on the forum
« on: April 20, 2017, 03:38:08 PM »
Which file would I need to place my custom function in so it can be called from anywhere on the forum? (2.0.13)

Offline Illori

  • Project Manager
  • SMF Master
  • *
  • Posts: 47,537
Re: Call a custom function from anywhere on the forum
« Reply #1 on: April 20, 2017, 03:45:05 PM »
can you provide some details as to what exactly you are wanting to do?

Offline MobileCS

  • Jr. Member
  • **
  • Posts: 117
Re: Call a custom function from anywhere on the forum
« Reply #2 on: April 20, 2017, 04:08:46 PM »
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.

Offline sǝๅqɯɐɥS

  • SMF Hero
  • ******
  • Posts: 4,425
  • Gender: Male
    • i30 Owners Club
Re: Call a custom function from anywhere on the forum
« Reply #3 on: April 20, 2017, 04:42:42 PM »
Then you have no choice other than to declare the function within index.php.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 67,579
    • Arantor on GitHub
Re: Call a custom function from anywhere on the forum
« Reply #4 on: April 20, 2017, 07:22:34 PM »
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 ?
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline MobileCS

  • Jr. Member
  • **
  • Posts: 117
Re: Call a custom function from anywhere on the forum
« Reply #5 on: April 20, 2017, 08:51:30 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 :)

Quote
this 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.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 67,579
    • Arantor on GitHub
Re: Call a custom function from anywhere on the forum
« Reply #6 on: April 21, 2017, 01:19:14 PM »
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.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 54,820
  • Gender: Male
    • Kindred-999 on GitHub
Re: Call a custom function from anywhere on the forum
« Reply #7 on: April 21, 2017, 01:33:49 PM »
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)
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline MobileCS

  • Jr. Member
  • **
  • Posts: 117
Re: Call a custom function from anywhere on the forum
« Reply #8 on: April 21, 2017, 03:49:03 PM »
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.


Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 67,579
    • Arantor on GitHub
Re: Call a custom function from anywhere on the forum
« Reply #9 on: April 21, 2017, 03:55:48 PM »
index.template.php is used literally everywhere. It's the header + footer for the site.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline richardwbb

  • Jr. Member
  • **
  • Posts: 254
  • currently reading; '$smcFunc'
Re: Call a custom function from anywhere on the forum
« Reply #10 on: April 30, 2017, 10:44:17 AM »
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].
Code: [Select]
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.