服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > OpenCart教程 >

opencart自动生成config.php文件脚本

时间:2016-04-16 02:58来源:未知 作者:最模板 点击:
opencart的数据库链接文件是config.php与admin/config.php,在网站搬家与网站路径变化时候,去修改网站配置文件特别麻烦,以下脚本可以解决这个问题,如命名为 zuimoban_config.php 代码如下:
opencart的数据库链接文件是config.php与admin/config.php,在网站搬家与网站路径变化时候,去修改网站配置文件特别麻烦,以下脚本可以解决这个问题,如命名为  zuimoban_config.php

代码如下:


<?php
 
//www.zuimoban.com
################################################################################
### 修改以下信息
################################################################################
 
$dbdriver = "mysql"; # Database driver
$dbhost = "localhost"; # Database host name
$dbname = "opencart_framework"; # Database name
$dbuser = "root"; # Database username
$dbpass = ""; # Database password
$prefix = "oc_"; # Database prefix tables
 
 
 
 
//最模板提供,QQ: #
 
################################################################################
### 以下信息无需修改
################################################################################
 
$file = fopen("config.php","w") or exit("NOT FOUND FILE!");
$content2 = "<?php
// HTTP
define('HTTP_SERVER', 'http://" . $_SERVER['HTTP_HOST'] .rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . "/');
define('HTTP_IMAGE', 'http://" . $_SERVER['HTTP_HOST'] .rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') ."/image/');
define('HTTP_ADMIN', 'http://" . $_SERVER['HTTP_HOST'] .rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') ."/admin/');
 
// HTTPS
define('HTTPS_SERVER', 'http://" . $_SERVER['HTTP_HOST'] .rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . "/');
define('HTTPS_IMAGE', 'http://" . $_SERVER['HTTP_HOST'] .rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') ."/image/');
 
// DIR
define('DIR_APPLICATION', '".realpath(dirname(__FILE__)) ."/catalog/');
define('DIR_SYSTEM', '".realpath(dirname(__FILE__)) ."/system/');
define('DIR_DATABASE', '".realpath(dirname(__FILE__)) ."/system/database/');
define('DIR_LANGUAGE', '".realpath(dirname(__FILE__)) ."/catalog/language/');
define('DIR_TEMPLATE', '".realpath(dirname(__FILE__)) ."/catalog/view/theme/');
define('DIR_CONFIG', '".realpath(dirname(__FILE__)) ."/system/config/');
define('DIR_IMAGE', '".realpath(dirname(__FILE__)) ."/image/');
define('DIR_CACHE', '".realpath(dirname(__FILE__)) ."/system/cache/');
define('DIR_DOWNLOAD', '".realpath(dirname(__FILE__)) ."/download/');
define('DIR_LOGS', '".realpath(dirname(__FILE__)) ."/system/logs/');
 
// DB
define('DB_DRIVER', '".$dbdriver."');
define('DB_HOSTNAME', '".$dbhost."');
define('DB_USERNAME', '".$dbuser."');
define('DB_PASSWORD', '".$dbpass."');
define('DB_DATABASE', '".$dbname."');
define('DB_PREFIX', '".$prefix."');
?>";
$success1 = fwrite($file, $content2);
fclose($file);
 
 
########## ADMIN ###########
$file = fopen("admin/config.php","w") or exit("NOT FOUND FILE!");
$content3 = "<?php
// HTTP
define('HTTP_SERVER', 'http://" . $_SERVER['HTTP_HOST'] .rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . "/admin/');
define('HTTP_CATALOG', 'http://" . $_SERVER['HTTP_HOST'] .rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') ."/');
define('HTTP_IMAGE', 'http://" . $_SERVER['HTTP_HOST'] .rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') ."/image/');
 
// HTTPS
define('HTTPS_SERVER', 'http://" . $_SERVER['HTTP_HOST'] .rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . "/admin/');
define('HTTPS_CATALOG', 'http://" . $_SERVER['HTTP_HOST'] .rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') ."/');
define('HTTPS_IMAGE', 'http://" . $_SERVER['HTTP_HOST'] .rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') ."/image/');
 
// DIR
define('DIR_APPLICATION', '".realpath(dirname(__FILE__)) ."/admin/');
define('DIR_SYSTEM', '".realpath(dirname(__FILE__)) ."/system/');
define('DIR_DATABASE', '".realpath(dirname(__FILE__)) ."/system/database/');
define('DIR_LANGUAGE', '".realpath(dirname(__FILE__)) ."/admin/language/');
define('DIR_TEMPLATE', '".realpath(dirname(__FILE__)) ."/admin/view/template/');
define('DIR_CONFIG', '".realpath(dirname(__FILE__)) ."/system/config/');
define('DIR_IMAGE', '".realpath(dirname(__FILE__)) ."/image/');
define('DIR_CACHE', '".realpath(dirname(__FILE__)) ."/system/cache/');
define('DIR_DOWNLOAD', '".realpath(dirname(__FILE__)) ."/download/');
define('DIR_LOGS', '".realpath(dirname(__FILE__)) ."/system/logs/');
define('DIR_CATALOG', '".realpath(dirname(__FILE__)) ."/catalog/');
 
// DB
define('DB_DRIVER', '".$dbdriver."');
define('DB_HOSTNAME', '".$dbhost."');
define('DB_USERNAME', '".$dbuser."');
define('DB_PASSWORD', '".$dbpass."');
define('DB_DATABASE', '".$dbname."');
define('DB_PREFIX', '".$prefix."');
?>";
$success2 = fwrite($file, $content3);
fclose($file);
 
 
if($success1 && $success2)
{
 echo "<p style='color: brown; text-align: center; margin: 200px auto; font-size: 120%;'>Install Successfully! </br> Please Delete Install.php File!</p>";
}else{
 echo "<p style='color: brown; text-align: center; margin: 200px auto; font-size: 120%;'>Install Failed! </br> Please configure Install.php File!</p>";
}
?>


 1.  上传这个脚本到 opencart 目录下 (/public_html)
  2. 配置这个文件里的顶部部分
 3. 在浏览器访问: http://www.yourdomain.com/zuimoban_config.php
 4. 删除 zuimoban_config.php

即可大功告成!
(责任编辑:最模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
热点内容