Preg_replace question

Advert test
#21
This is the file its modifying but there will be more functions added down the road.
<?php

$DBHost = '';
$DBName = '';
$DBUser = '';
$DBPass = '';
$DBPrefix = '';

function getDBHost() {
global $DBHost;
return $DBHost;
}
function getDBName() {
global $DBName;
return $DBName;
}
function getDBUser() {
global $DBUser;
return $DBUser;
}
function getDBPass() {
global $DBPass;
return $DBPass;
}
function getDBPrefix() {
global $DBPrefix;
return $DBPrefix;
}
?>
 
#22
Because the file is PHP, is there a chance the server will process the file on request?
What about trying the save the file as .txt and give it another go?
 
#24
Yes you can,so lets see what I can come up with this minute.
Change your php file with the following code:

$DBHost = '[dbhost]';
$DBName = '[dbname]';
$DBUser = '[dbuser]';
$DBPass = '[dbpass]';
$DBPrefix = '[dbprefix]';

function getDBHost() {
global $DBHost;
return $DBHost;
}
function getDBName() {
global $DBName;
return $DBName;
}
function getDBUser() {
global $DBUser;
return $DBUser;
}
function getDBPass() {
global $DBPass;
return $DBPass;
}
function getDBPrefix() {
global $DBPrefix;
return $DBPrefix;
}

:::::::::::::::::::::::::::::::::
Now forget about preg_replace and try str_replace

function setDBDetails($DBHost,$DBName,$DBUser,$DBPass,$DBPrefix) {
global $configFileLoc;
$fhandle = fopen($configFileLoc,"r");
$content = fread($fhandle,filesize($configFileLoc));
//echo $content;
//echo "<hr />";
$find = array("[dbhost]","[dbname]","dbuser]","[dbpass]","[dbprefix]");
replace = array("DBHOST","DBNAME","DBUSER","DBPASS","DBPREFIX");
$content = str_replace($find, $replace, $content);
//echo $content;
//echo "<hr />";
$fhandle = fopen($configFileLoc,"w");
fwrite($fhandle,$content);
fclose($fhandle);
//echo $content;
}

But your file must have read & write permission setup on the server which is NOT SAFE
 
#25
This works fine, thanks louie. What would you recommend for a secure way of storing and being able to retrieve the details via PHP?
 
#26
It's alright the way it is if only done once at the setup time.
Once done, check and make sure the permission to write to the file is changed.
Something like Wordpress does it.
If that's not the case I highly not recommended.
 
Top