PHP forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.
April 2024
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
282930    

Calendar Calendar

Latest topics
» Kabaddi, Kabaddi, Kabaddi, Kabaddi......PHP?
updating configuration file in browser EmptyFri Jul 22, 2011 1:37 pm by shyamsunder

» Thousands of Free PHP Scripts Recommended
updating configuration file in browser EmptyWed May 18, 2011 10:33 am by bizboy12

» PHP form validation problem?
updating configuration file in browser EmptyWed Jan 12, 2011 1:25 pm by simy202

» string wrap
updating configuration file in browser EmptySat Aug 02, 2008 2:06 pm by scvinodkumar

» retrieving current date rows
updating configuration file in browser EmptyTue Jul 15, 2008 3:25 am by scvinodkumar

» number in words
updating configuration file in browser EmptyTue Apr 29, 2008 3:10 pm by scvinodkumar

» Simple PHP Form Field Generator
updating configuration file in browser EmptyFri Apr 25, 2008 12:28 pm by scvinodkumar

» PHP password generator
updating configuration file in browser EmptyFri Apr 18, 2008 7:24 pm by scvinodkumar

» PHP Script to Extract Email Address from any text
updating configuration file in browser EmptyFri Apr 18, 2008 7:18 pm by scvinodkumar

Search
 
 

Display results as :
 


Rechercher Advanced Search

Affiliates
free forum
 


Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

updating configuration file in browser

Go down

updating configuration file in browser Empty updating configuration file in browser

Post  scvinodkumar Sat Mar 29, 2008 10:05 pm

filename:setup.php
<?php
// USAGE: http://setup.php?strCfgFile=FILE_TO_EDIT
// Example: http://setup.php?strCfgFile=sample.inc.php
*/
$strCfgFile = $_REQUEST['strCfgFile'];
if(!ISSET($strCfgFile)) {
echo 'You did not specify any file to edit.<br>';
echo 'Please call this page like setup.php?strCfgFile=YOUR_FILE';
exit();
}

function ReplaceConfValue($strCfgFile,$strCfgVar,$strCfgVal)
{
$strOldContent = file ($strCfgFile);
$strNewContent = "";
while (list ($intLineNum, $strLine) = each ($strOldContent))
{
if(eregi("^\\$".$strCfgVar."( |\t)*=",$strLine)) // show any line beginning with a $
{
$strLineParts=explode("=",$strLine);
// we should determine type of value here! (BOOL, INT or String)
if("$".$strCfgVar == trim($strLineParts[0]))
{
$strLineParts[1] = "\t\"".$strCfgVal."\"";
$strLine = implode("=",$strLineParts).";\r\n";
}
}
$strNewContent .= $strLine;
$fp = fopen($strCfgFile."_new", "w");
fputs($fp,$strNewContent);
fclose($fp);
}
echo "<center><pre>The value for <b>$$strCfgVar</b> has been replaced with <b>$strCfgVal</b> in File <b>$strCfgFile</b></pre></center>";
if(!rename($strCfgFile,$strCfgFile.".bak")) echo "<pre><b>Error: Could not rename old file!</b></pre>";
if(!rename($strCfgFile."_new",$strCfgFile)) echo "<pre><b>Failed to copy File!</b></pre>";
}



//=================== Begin OUTPUT ===========================?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Setupscript</title></head>
<body>
<script language="JavaScript">
<!--
function GetVarValue(field){
selected=false;
for (Count = 0; Count < document.selectform.strCfgVar.length; Count++){
if(document.selectform.strCfgVar[Count].selected){
selected=true;
var string = document.selectform.strCfgVar[Count].value;
var stringArray = string.split("-/-");
strCfgVarValue = stringArray[1];
strCfgCommentValue = stringArray[2];
}
}
if ((navigator.appName.indexOf("Microsoft") != -1) && (parseInt(navigator.appVersion) >= 4)){
document.selectform.currVal.style.backgroundColor="yellow";
}
document.selectform.currVal.value=strCfgVarValue;
document.selectform.strCfgValNew.value=strCfgVarValue;
document.selectform.comment.value=strCfgCommentValue;
document.selectform.strCfgValNew.focus();
return true;
}
//-->
</script>

<table width="100%" heigth="100%" border="0">
<tr>
<td>
<table align="center" cellpadding="3" cellspacing="3" border="0">
<tr>
<form method="POST" name="selectform" action="<? echo $PHP_SELF ?>">
<input type="hidden" name="strCfgFile" size="20" value="<? echo $strCfgFile ?>">
<td>
Variable:&nbsp;
</td>
<td>
<select name="strCfgVar" onChange="GetVarValue(this)">
<option value=""></option>
<?php
include($strCfgFile);
$strContent = file ($strCfgFile);
while (list ($intLineNum, $strLine) = each ($strContent)){
if(eregi("^\\$",$strLine)){ // show any line beginning with a $
$strLineParts=explode("=",$strLine);
$var = ereg_replace("[$\t ]","",($strLineParts[0]));
$val = ereg_replace("//.*","",trim($strLineParts[1]));
$comment = str_replace($val,"",$strLineParts[1]);
$comment = ereg_replace("[$/]","",trim($comment));
if(!eregi("\[",$var)){
echo '<option value="'.$var.'-/-'.$$var.'-/-'.$comment.'">'.$var.'</option>';
}
}
}
?>
</select>
</td>
<td>
Current Value: <input type="text" name="currVal" size="30">
</td>
<td>
New Value: <input type="text" name="strCfgValNew" size="20">
</td>
</tr>
<tr>
<td colspan="4">
<input type="submit" value="Submit Changes" name="DoChange">
</td>
</tr>
<tr>
<td colspan="4" align="right">
Note: <textarea cols="50" rows="5" wrap="hard" name="comment" onBlur="return false;"></textarea>
</td>
</tr>
</table>
</td>
</tr>


<?php if($DoChanges){
$strCfgVars=split("-/-",$strCfgVar);
ReplaceConfValue($strCfgFile,$strCfgVars[0],$strCfgValNew);
?>
<form method="POST" name="selectform" action="<? echo $PHP_SELF ?>">
<input type="hidden" name="strCfgFile" value="<? echo $strCfgFile ?>">
<input type="submit" name="done" value="More changes..">
</form>
<?php } ?>
</table>

</body>
</html>


filename: sample.conf.php
<?php
// sample configuration file for testing setup.php
$cfgDbHost = "localhost"; //Name of DB-Server
$cfgDbUser = "root"; //Name of DB User
$cfgDbPass = ""; //Password for DB Admin
$cfgDatabase = "Database"; //Name of database for this app
$cfgDbCreated = 0; //Time, the database has been created, (0) if not yet
$cfgDatabaseUser = "Database1"; //name of database, which contains usertable, if necessary
$cfgAppTable = "guestbook"; //name of this app
$cfgDomainName = "my-domain.com"; //name of domain, this app is installed
$cfgAdminUser = "admin"; //name of masteradmin
$cfgAdminPassword = "password"; //password for masteradmin
$cfgEnableUpload = 1; // specifies, whether uploads are allowed or not (1=allowed,0=not allowed)
$test = "vinod testing the file vinod testing the file vinod testing the file vinod testing the file vinod testing the file vinod testing the file vinod testing the file vinod testing the file ";

?>

scvinodkumar
Admin

Posts : 40
Join date : 2008-01-30

https://solutions.aforumfree.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum