繁体   English   中英

PHP安装创建包含变量的config.php

[英]PHP install create a config.php with variables included

我做了一个安装程序,将生成一个看起来像这样的config.php:

<?php 

$dbhost = "localhost";  // The host which hosts your database
$dbuser = "root";   // The user for the host/database
$dbpass = "";   // The users password
$dbname = "donationkeys";   // The name of the database which holds the activationkeys and notifications table

$colorscheme = "white";     // Choose from "white" or "black"

$config_gmail           =   true;                               //  Are we using gmail?
$config_gmail_username  =   "";     //  GMail username
$config_gmail_password  =   "";                     //  GMail password

$config_merchant_domain =   "merchant@domain.com";                  //  The email you want to appear on the email
$config_merchant_name   =   "merchant name";                    //  The name you want to appaer on the email

$config_merchant_email  =   "";             //  IMPORTANT! The email you use with paypal to receive payment

$config_USD             =   true;                           //  Currency, set this to false if using �'s i.e. GBP


// Below is the config for your own reference and the IPN. This will not affect your payment link on your donation page.
// You configure the payment links etc in index.html. Just to re state. This is for paypals verification only!

$config_options = array(

    "1k"=>array(
        "title"         => "1k in-game cash",
        "price"         => 1,
        "description"   => "This will give you 1,000 in-game cash and donator status.",
        "number"        => 1
    ),
    "5k"=>array(
        "title"         => "5k in-game cash",
        "price"         => 5.00,
        "description"   => "This will give you 5,000 in-game cash and donator status.",
        "number"        =>  2
    ),
    "10k"=>array(
        "title"         => "10k in-game cash",
        "price"         => 10.00,
        "description"   => "This will give you 10,000 in-game cash and donator status.",
        "number"        => 3
    ),
    "50k"=>array(
        "title"         => "50k in-game cash",
        "price"         => 20.00,
        "description"   => "This will give you 50,000 in-game cash and VIP status.",
        "number"        => 4
    )
);

?>

这是我的安装脚本的代码:

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST"){
    $username = $_POST['un'];
    $password = $_POST['pw'];
    $database = $_POST['db'];
    $apikey = $_POST['ak'];
    $host = $_POST["hn"];
    $email = $_POST["pp"];
    $server = $_POST["sn"];
    $currency = $_POST["cu"];
    if(!empty($username) && !empty($password) && !empty($database)) {
    if(empty($host)){ $host = "localhost"; }
    $file_contents = "<?
    /* MySQL Information */
    '$dbuser' = '$username';

    ?>";

    $file_contents2 = "<?
    \$API_KEY = '$apikey';
    ?>
    ";
    file_put_contents('../inc/config.php', $file_contents, FILE_APPEND | LOCK_EX);
    file_put_contents('../inc/apikey.php', $file_contents2, FILE_APPEND | LOCK_EX);
    include('success.php');

    } 
    else {
        header('Location: index.php');
    }
} else {
    header('Location: index.php');
}

?>

问题是当它生成config.php ,我希望它以如下方式打印配置:

$dbuser = "blah blah"

但问题是,它的打印方式如下:

'' = "blah blah"

请帮忙!

当使用双引号时,您必须转义变量,否则PHP假定他必须解析该variabele(尽管它可能不存在)。 在“真实”变量之间使用括号也是一种好习惯。

您也可以使用单引号,然后不必将其转义。

$file_contents = "<?
  /* MySQL Information */
  '\$dbuser' = '{$username}';

  ?>";

要么

$file_contents = '<?
  /* MySQL Information */
  $dbuser = "' .$username . '";

  ?>';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM