search
HomeBackend DevelopmentPHP TutorialHow to update configuration information with copy function in php

How to update configuration information with copy function in php

Jun 09, 2018 pm 04:22 PM
phprenewConfiguration file

This article mainly introduces the method of updating configuration information by copy function in php. Interested friends can refer to it. I hope it will be helpful to everyone.

The example in this article describes how PHP uses the COPY function to update the configuration file. The details are as follows:

_saveconfig.php file is as follows:

<?php
/*
 * File: _saveconfig.php
 * 
 * Modified: 2010-7-11
 * By:liulang
 * 说明:涉及到两个文件:_saveconfig.php和config.php当对后台的一些全局配置变量进行更新时,
 * 就更改后台的config.php然后通过这个文件更改前台的config.php文件(前后台文件都一样),
 * 这个是我曾经用过的一个方法,觉得还不错,拿出来与大家分享
 *
 * Created: 2010-6-20
 * By: liulang (xujiaphp@gmail.com)
 * 
 */
  $srcFile = &#39;../&#39;.$dRootDir.&#39;#data/config.php&#39;;
  $dstFile = $dRootDir.&#39;config.php&#39;; 
  $content = file_get_contents($srcFile);
  $arr = array
  (
     array(&#39;SITENAME&#39;, $gSite[&#39;siteName&#39;]),
     array(&#39;SITENAMEEN&#39;, $gSite[&#39;siteNameEn&#39;]),
     array(&#39;SITEKEYWORDS&#39;, $gSite[&#39;siteKeywords&#39;]),
     array(&#39;SITEDESCRIPTION&#39;, $gSite[&#39;siteDescription&#39;]),
     array(&#39;URLPREFIX&#39;, $gUrlPrefix),
     array(&#39;DBHOST&#39;, $gDb[&#39;host&#39;]),
     array(&#39;DBUSER&#39;, $gDb[&#39;user&#39;]),
     array(&#39;DBPWD&#39;, $gDb[&#39;pwd&#39;]),
     array(&#39;DBNAME&#39;, $gDb[&#39;db&#39;]),
     array(&#39;DBPREFIX&#39;, $gDb[&#39;prefix&#39;]),
     array(&#39;DIR&#39;, $gUpload[&#39;dir&#39;]),
     array(&#39;IMAGEWIDTH&#39;, $gUpload[&#39;imageWidth&#39;]),
     array(&#39;IMAGEHEIGHT&#39;, $gUpload[&#39;imageHeight&#39;]),
     array(&#39;CONTACTUS&#39;, $contactus),
     array(&#39;MENUHIDDENp&#39;, $menuhiddenp),
     array(&#39;THEME&#39;, $gTheme),
     array(&#39;DATE&#39;, date(&#39;Y-m-d&#39;)),
     array(&#39;USER&#39;, $dAdminName)
   );
   for ($i = 0; $i < count($arr); $i++)
   {
    $content = str_replace(&#39;~`~&#39;.$arr[$i][0].&#39;~`~&#39;, $arr[$i][1], $content);
   } 
   copy($dRootDir.&#39;config.php&#39;, $dRootDir.&#39;bak.config.php&#39;);
   //copy($dRootDir.&#39;bak.config.php&#39;, &#39;../&#39;.$dRootDir.&#39;config.php&#39;);
   $done = file_put_contents($dstFile, $content);
   copy($dstFile, &#39;../&#39;.$dRootDir.&#39;config.php&#39;);
?>

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 = &#39;1.0&#39;;
  $gDb = array
  (
    &#39;host&#39; => &#39;localhost&#39;,   //主机名
    &#39;user&#39; => &#39;root&#39;,   //用户名
    &#39;pwd&#39; => &#39;&#39;,    //密码
    &#39;db&#39; => &#39;sino&#39;,    //数据库名
    &#39;prefix&#39; => &#39;sin_&#39;  //数据库前缀
  );
  $gSite = array
  (
    &#39;siteName&#39; => &#39;公司名&#39;,   
    &#39;siteNameEn&#39; => &#39;we are the company&#39;,  
    &#39;siteKeywords&#39; => &#39;药物,医药,制药&#39;,  
    &#39;siteDescription&#39; => &#39;公司名是一家从事00方面的公司&#39; 
  );
  $gUpload = array
  (
    &#39;dir&#39; => &#39;uploads&#39;,
    &#39;imageWidth&#39; => &#39;120&#39;,
    &#39;imageHeight&#39; => &#39;*&#39;  
  );
  $contactus = &#39;&#39;;
  $menuhiddenp = "";
  $FROMURL=$_SERVER["HTTP_REFERER"]?$_SERVER["HTTP_REFERER"]:$HTTP_SERVER_VARS["HTTP_REFERER"];
  $dRootDir = &#39;../&#39;;
  $conn = mysql_connect($gDb[&#39;host&#39;],$gDb[&#39;user&#39;],$gDb[&#39;pwd&#39;]);
  mysql_select_db($gDb[&#39;db&#39;]) or die(&#39;database connect error!&#39;); 
  mysql_query("SET NAMES &#39;gbk&#39;"); 
?>

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

PHP’s four basic sorting algorithms and two search algorithms

PHP generates and downloads csv files and solves problems

php three recursive function implementation methods

The above is the detailed content of How to update configuration information with copy function in php. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software