0

I have a config.ini file with some values. One of them is the path to the root of my script. So in my js file i get the content from the config.ini file, but i have one big mistake. To load the data from the config file i already need one value from the config file, namely the path to the config file.

Any idea how to handle that?

Regards Sylnois

Edit:

This is my htaccess:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}  -d

RewriteRule  ^.*$  -  [L]

RewriteRule ^([^/]+)/$  index.php?token=$1 [L]

This rewrites my link from http://domain.com/fun/bla/index.php?token?123 to http://domain.com/fun/bla/123/ .. So if someone access the second link, my js script would not be run anymore, cause i work with relative paths. I have now a value in my config which points to the root directory of my applicatoin: "./fun/bla/". Everything works so fine. But my requirement are, that no paths should be implemented in my code.

Sylnois
  • 1,589
  • 6
  • 23
  • 47

3 Answers3

2

Yes. Store the path to your config file in code. The rest can be loaded from the config file.

You can't possibly have everything in a config file. I once worked with someone who tried to store database configuration in the database. And then realized their mistake when they tried to make the application, you know, work.

Colin M
  • 13,010
  • 3
  • 38
  • 58
  • Same to you. I have a link like http://domain.com/fun/bla/ In there is my application with all my files. My htaccess rewrite my url from http://domain.com/fun/bla/index.php?bla=123 to http://domain.com/fun/bla/123/ So my script can't run anymore, if i have not a path like that in my config file "/fun/bla". – Sylnois Feb 12 '13 at 15:11
  • Give me a minute, i'll give you more information in the question. – Sylnois Feb 12 '13 at 15:11
0

What I've always done is to statically define the name of the config file in my code, so in your JS:

config_file = '/path/to/myconfig.ini'
Aurelia Peters
  • 2,169
  • 1
  • 20
  • 34
0

This is a chicken and egg problem. The config file cannot contain the path to the config file, its path needs to be known to all parts of the program that need to know the settings. Perhaps have the path as a global variable in your program somewhere?

Husman
  • 6,819
  • 9
  • 29
  • 47
  • My problem is, that i have htaccess with fake directories rules. So if someone uses this kind of fake directories, the path would not be right anymore. – Sylnois Feb 12 '13 at 15:08
  • It makes perfect sense to hardcode the path to the config. And then have the rest of the config options in that file. The path can be set as a hard coded file path '/var/www/project/config.ini', and changed everytime the htaccess changes the path for the config file. – Husman Feb 12 '13 at 15:13
  • The other option is to do a file structure search from the root of the project directory for config.ini - which is slow, but then you dont have to worry about its location, as long as it exists somewhere in the project. – Husman Feb 12 '13 at 15:14
  • see updated question. I can't use paths in my code. If you tell me, that there is now way to do it like i wish, than would be that also enough. So i would just create a js-global-var for the path. – Sylnois Feb 12 '13 at 15:19