PHP using the copy function to update the configuration file method, _php tutorial

Source: Internet
Author: User

PHP uses the copy function to update the configuration file method,


This example describes how PHP updates a configuration file using the copy function. Share to everyone for your reference. Specific as follows:

The _saveconfig.php file is as follows:

<?php/* * File: _saveconfig.php * * modified:2010-7-11 * By:liulang * Description: involves two files: _saveconfig.php and config.php when the background of some of the global distribution When the variable is updated, * Change the background of the config.php and then change the foreground config.php file through this file (the former background files are the same), * This is a method I have used, feel good, take it out to share with you * * created:2010-6-20 * By:liulang (xujiaphp@gmail.com) * */$srcFile = '. /'. $dRootDir. '  #data/config.php ';   $dstFile = $dRootDir. ' config.php ';  $content = file_get_contents ($srcFile); $arr = Array (' SITENAME ', $gSite [' SITENAME ']), array (' Sitenameen ', $gSite [' Sitenameen ']), array (' Sitek Eywords ', $gSite [' sitekeywords ']), array (' sitedescription ', $gSite [' sitedescription ']), array (' URLPrefix ', $gUrlPr Efix), Array (' Dbhost ', $gDb [' Host ']), array (' DBUSER ', $gDb [' User ']), array (' Dbpwd ', $gDb [' pwd ']), array (' D Bname ', $gDb [' DB ']), array (' Dbprefix ', $gDb [' prefix ']), Array (' dir ', $gUpload [' dir ']), array (' ImageWidth ', $gU pload[' ImageWidth '), Array (' ImageHeight ', $gUpload [' ImageHeight ']), array (' ContactUs ', $contacTUS), array (' Menuhiddendiv ', $menuhiddendiv), Array (' THEME ', $gTheme), Array (' Date ', date (' y-m-d ')), array   (' USER ', $dAdminName)); for ($i = 0; $i < count ($arr), $i + +) {$content = Str_replace (' ~ ' ~ '. $arr [$i][0]. '   ~ ' ~ ', $arr [$i][1], $content);   Copy ($dRootDir. ' config.php ', $dRootDir. ' bak.config.php '); Copy ($dRootDir. ' bak.config.php ', '.   /'. $dRootDir. ' config.php ');   $done = File_put_contents ($dstFile, $content); Copy ($dstFile, '.. /'. $dRootDir. ' config.php ');? >

The

config.php configuration file is as follows:

<?php/* * File:config.php * * modified:2010-09-20 * by:admin * * created:2010-6-20 * By:liulang  (xujiaphp@gmail.com) * */$gVersion = ' 1.0 '; $gDb = Array (' host ' = ' localhost ',//hostname ' user ' = ' root ',//username ' pwd ' = ', '//password ' db ' =& Gt  ' Sino ',//database name ' prefix ' = ' sin_ '//database prefix); $gSite = Array (' siteName ' = ' Company name ', ' sitenameen ' = ' We Are ', ' the ', ' sitekeywords ' and ' = ' drugs,  Pharmaceuticals, pharmaceuticals ', ' sitedescription ' = ' = ' Company name is a company engaged in 00 aspects ');  $gUpload = Array (' dir ' = ' uploads ', ' imagewidth ' = ' + ', ' imageheight ' = ' * ');  $contactus = ";  $menuhiddendiv = "";  $FROMURL =$_server["Http_referer"]?$_server["Http_referer"]: $HTTP _server_vars["Http_referer"]; $dRootDir = '.  /';  $conn = mysql_connect ($gDb [' Host '], $gDb [' User '], $gDb [' pwd '];   mysql_select_db ($gDb [' db ']) or Die (' Database connect error! '); mysql_query ("SET NAMES ' GBK '");; 

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1019071.html www.bkjia.com true http://www.bkjia.com/PHPjc/1019071.html techarticle PHP uses the copy function to update the configuration file, and this example describes how PHP uses the copy function to update the configuration file. Share to everyone for your reference. Specific as follows: _saveconfig ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.