Destramic Posted November 24, 2006 Share Posted November 24, 2006 my idea is to open configuration.php in replace.php and redefine the value of $WEBSITE_URI ans save it?is this possible?thank destramicconfiguration.php[code]// Website URIdefine("WEBSITE_URI", "www.domain.co.uk");[/code][code]...[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28352-redefining-defined-vars-and-saving/ Share on other sites More sharing options...
wildteen88 Posted November 24, 2006 Share Posted November 24, 2006 You will have to use fopen and dread functions. Then using a regular expression you can search for the following line:define("WEBSITE_URI", "www.domain.co.uk");and redefine its value. Quote Link to comment https://forums.phpfreaks.com/topic/28352-redefining-defined-vars-and-saving/#findComment-129686 Share on other sites More sharing options...
Destramic Posted November 24, 2006 Author Share Posted November 24, 2006 thank you for your replywildteen88 i thought there might of been a easier way...but this is what ive done so far..doesnt work...dont think the regual expression is right...can you help?[code] $file = $document_root . "/core/configuration.php"; // Check if file exists if (file_exists($file)) { // Open configuration file $handle = fopen($file, "w+"); $contents =ob_get_contents(); $replace = preg_match("define(/\"WEBSITE_URI\", \"[^\.\/]\"/);", $var, $contents); $write = fputs ($handle, $string); // Close opened file fclose($handle); } else { echo "Unable to configuration file.<br />\n"; }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28352-redefining-defined-vars-and-saving/#findComment-129779 Share on other sites More sharing options...
wildteen88 Posted November 25, 2006 Share Posted November 25, 2006 A bit bloated but works:[code=php:0]$file = $document_root . "/core/configuration.php";// Check if file existsif (file_exists($file)){ // Open configuration file $handle = fopen($file, "r+"); $config_content = fread($handle, filesize($file)); fclose($handle); $handle = fopen($file, "w"); $var = 'www.google.com'; $string = preg_replace("#define\(\"WEBSITE_URI\", \"(.*?)\"\);#", "define(\"WEBSITE_URI\", \"$var\");", $config_content); $write = fputs($handle, $string); fclose($handle);}else{ echo "Unable to configuration file.<br />\n";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28352-redefining-defined-vars-and-saving/#findComment-130046 Share on other sites More sharing options...
Destramic Posted November 25, 2006 Author Share Posted November 25, 2006 thank you...that works great Quote Link to comment https://forums.phpfreaks.com/topic/28352-redefining-defined-vars-and-saving/#findComment-130220 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.