I’m looking to find a way to make a config.php
file to setup the website easier. See below;
config.php –
#Community Name $commname = "Community A", #Community Phone Number $commphone = "0123456789",
index.php –
<h1>Community Name: <?php echo($commname) ?></h1> <h2>Phone Number: <?php echo($commphone) ?></h2>
contact.php (same setup, just a different page) –
<h1>Community Name: <?php echo($commname) ?></h1> <h2>Phone Number: <?php echo($commphone) ?></h2>
I’m fairly new to PHP so I’m not sure if echo
is the best way to do it or not.
Thanks!
Advertisement
Answer
Ye so just create a config.php
<?php $serverName = "Server Name"; ?>
Then inside your other php files include the config file by doing
<?php require_once(__DIR__ . "/config.php"); ?>
Then where you want to use the variable do
<title> <?php echo $serverName; ?> </title>