note 129279 added to function.parse-ini-file
| From: | theking2(at)king.ma | Date: | Mon, 26 Feb 2024 08:18:58 +0000 |
| Subject: | note 129279 added to function.parse-ini-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221208@lists.php.net to get a copy of this message | ||
To make the content available in every corner of you application I use a user defined constant.
$SETTINGS. It is initialized like this
<?php
define( 'SETTINGS", parse_ini_file('settings.ini', true) );
?>
With the proper settings.ini file you can now do stuff like
<?php
$db = new \PDO(
"mysql:host={SETTINGS['db']['host']};dbname={SETTINGS['db']['name']};charset=utf8",
SETTINGS['db']['user'],
SETTINGS['db']['pass'], [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
]
);
?>
Make sure to hide your settings.ini file on a website with for instance
<?php
<FilesMatch "\.(?:ini|htaccess)$">
Order allow,deny
Deny from all
</FilesMatch>
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.131 (proxied: 46.140.241.51)
----
Manual Page -- https://php.net/manual/en/function.parse-ini-file.php
Edit -- https://main.php.net/note/edit/129279
Del: integrated -- https://main.php.net/note/delete/129279/integrated
Del: useless -- https://main.php.net/note/delete/129279/useless
Del: bad code -- https://main.php.net/note/delete/129279/bad+code
Del: spam -- https://main.php.net/note/delete/129279/spam
Del: non-english -- https://main.php.net/note/delete/129279/non-english
Del: in docs -- https://main.php.net/note/delete/129279/in+docs
Del: other reasons-- https://main.php.net/note/delete/129279
Reject -- https://main.php.net/note/reject/129279
Search -- https://main.php.net/manage/user-notes.php