Advertisement:

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

Online MobileCS

  • Semi-Newbie
  • *
  • Posts: 81
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: 46,118
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?

Online MobileCS

  • Semi-Newbie
  • *
  • Posts: 81
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 Shambles

  • SMF Hero
  • ******
  • Posts: 4,165
  • 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: 66,702
    • 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.

Online MobileCS

  • Semi-Newbie
  • *
  • Posts: 81
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: 66,702
    • 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.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 54,071
  • 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.

Online MobileCS

  • Semi-Newbie
  • *
  • Posts: 81
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: 66,702
    • 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.