php - 如何更新php中定义的变量?
问题描述
我正在学习一些PHP
编码,并且正在创建一个简单的config.php
文件。我API_URL
为我的本地服务器定义了一个用于测试的配置文件。
<?php
DEFINE("API_URL", "http://localhost:8000/api");
?>
我希望API_URL
在用于登台服务器时对其进行更新。例如,我有另一个php
脚本将更新所说的API_URL
.
<?php
require_once "config.php";
$API_URL = API_URL;
// Here I want to update the API_URL in config file to be something like
// DEFINE("API_URL", "https://mystagingsite.com/api");
// And I want this new "API_URL" to be updated in config.php file.
// How will I do that?
?>
解决方案
您可以从$_SERVER
. 您可以使用:$_SERVER['HTTP_HOST'];
所以你可以像这样使用 API URL:
$api_url = $_SERVER['HTTP_HOST'].'/api/';
DEFINE('APIURL',$api_url);
推荐阅读
- algorithm - 你能开发一个在给定特定时间复杂度下运行的算法吗?
- r - 将数据转换为矩阵后如何按列制作词频表和词云?尺寸小,贴工作R代码
- sql - 没有连接的 SQL 查询
- java - 无法从 Firebase 实时数据库 Android 检索数据
- swift - 设置 SwiftUI 变量
- node.js - 一种从 NodeJS 中的音频文件获取音量级别的方法
- javascript - 为什么 React 在没有被点击的情况下调用 onClick 函数?
- bash - 通过 ssh 运行 bash 显示错误:/usr/bin/env: bash: No such file or directory
- wordpress - 在 Wordpress 中如何加载 functions.php?
- php - PHP路由不包括文件