0

I am learning some PHP coding and I am creating a simple config.php file. I that config file I have defined an API_URL for my local server for testing.

<?php
    DEFINE("API_URL", "http://localhost:8000/api"); 
 ?>

I want this API_URL to be updated when used to staging server. For example I have this another php script that will update the said 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?
?>

1 Answer 1

1

You can take dynamic variables from $_SERVER. You can use: $_SERVER['HTTP_HOST'];

So you can use like this API URL:

$api_url = $_SERVER['HTTP_HOST'].'/api/';
DEFINE('APIURL',$api_url);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.