1

You are about to send an email using the outgoing email api. At this time, access_token only needs to be acquired once, so I want to run the authentication process once and share it in several sessions without renewing the key until the key expires. Usually, if you save it to a database or to a file, you will be able to access it anywhere within php of the Apache web server. However, I would like to ask you how about saving it in a better place than saving it in this database or file. For example, isn't it a good idea to store it in php's super global variable?

if($_GLOABLS['token'] != null) 
    $_GLOABLS['token'] = access_token;
DuRu Kang
  • 23
  • 5
  • 3
    _"isn't it a good idea to store it in php's super global variable?"_ - those live only as long, as the current script instance is running. Script ends - all globals are gone as well. – CBroe Aug 05 '22 at 12:20
  • 2
    Why do you think a database isn't a good place? What problem are you having? – ADyson Aug 05 '22 at 12:43
  • 1
    Did the answer below help ? – Rohit Gupta Aug 07 '22 at 23:37
  • @RohitGupta Mr Rohit Gupta: The answer below was very helpful. We are going to discuss this issue with our colleagues who work with us, and all of our team members are very grateful for your professional opinion. – DuRu Kang Aug 08 '22 at 09:44
  • Great. do you mind ticking it etc. – Rohit Gupta Aug 08 '22 at 11:32

1 Answers1

2

Another place where you can store some information is the environment. I wouldn't put loads of variables there, but a few is fine.

I actually use it for a few variables that are different between production and development. This way, the source files can be identical.

If you have access to the php.ini files then you can store it in there.

If you are using apache and have access to .htaccess file, then you can store like this

setenv My_Variable value

If you are using xampp, then you can place it in F:\xampp\apache\conf\extra\httpd-xampp.conf

SetEnv PHP_DEBUG 1

And you can read it in your php as

$MyVariable   = getenv('My_Variable');     
$Debug = (getenv('PHP_DEBUG'));     
Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41