Jump to content


Photo

Changing a Value in a config.php


  • Please log in to reply
6 replies to this topic

#1 shimano55

shimano55
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationLos Angeles, CA

Posted 14 April 2006 - 05:13 PM

Hey everyone. I need to know how to use php to change the value of a variable in my configuration file and resave the file with the variable having its new value. For instance, I want to change:

$var1 = 1;
to
$var1 = 0;

and then save the file with the new value for $var1.

Thanks,
shimano55
PHP is my life.

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 14 April 2006 - 05:26 PM

You will want to look at [a href=\"http://uk.php.net/manual/en/function.fopen.php\" target=\"_blank\"]fopen[/a] and [a href=\"http://uk.php.net/manual/en/function.fwrite.php\" target=\"_blank\"]fwrite[/a] for what you want to do.

#3 lansing

lansing
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationClinton, TN USA

Posted 14 April 2006 - 05:27 PM

I don't know if I just missed something, but what formate is the configuration file? If it is .php then just use wordpad & just save it.

#4 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 14 April 2006 - 07:05 PM

[!--quoteo(post=364847:date=Apr 14 2006, 12:27 PM:name=lansing)--][div class=\'quotetop\']QUOTE(lansing @ Apr 14 2006, 12:27 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I don't know if I just missed something, but what formate is the configuration file? If it is .php then just use wordpad & just save it.
[/quote]


"I need to know how to use php to change the value of a variable in my configuration file"

#5 sneskid

sneskid
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 14 April 2006 - 07:53 PM

wildteen88 has the right answer

the php configuration file is a .ini file, you'll have to write some code to safely change the variables without messing the file up... maybe such code already exists, search google for it.

some hosts don't give you access to the ini file though.

There are also some ini values you can temporarily change (more like ignore) while the script is running. I know that's not what you wan't to do.. but just letting you know it's possible.


Edit:

Opps... I think I missunderstood what you meant by "configuration file"... are you talking about the main php ini file... or a file you've made?
Still tho.. wildteen88 has the right answer

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 14 April 2006 - 08:30 PM

You should look at the function [a href=\"http://www.php.net/parse_ini_file\" target=\"_blank\"]parse_ini_file[/a]() and see if that helps you.

Ken

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 15 April 2006 - 08:19 AM

Umm, I dont think shimano55 wants to edit his php.ini file but a configuration file, ie config.php, for his script to edit a the value of $var1 to 0. shimano55 doesn't want to edit the php.ini.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users