Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[PHP] Variables in a config file

Zzzz...
Loyal Member
Joined
Dec 26, 2008
Messages
781
Reaction score
225
This is an extremely simple tutorial, I'll make one later about how to incorporate databases into this, for now it'll be file-based.

What does this do?
This tutorial will teach you how you can make a configuration file for users to fill information out in. The filled out information can be used easily across the site

Step 1.
Make two files: config.php and index.php

inside of index.php put the following code:
Code:
<?php
include('config.php');
?>

<title><?php echo $title; ?> - Index</title>

Welcome to <?php echo $title; ?>! This website was made by <?php echo $name; ?>.

Step 2.
inside of config.php put the following code:
Code:
<?php
$title = "Website"; 	/* The name of your website */
$name = "Name"; 		/* Your name */
?>
You can change the variables in config.php to change what is displayed on the site

About the code
First part of the code, the <?php and ?> tags
Code:
<?php
PHP CODE
?>
The PHP tags will make the inside code PHP code

----------------------------------------------------------------------------------------------------------------------------------------------------

include('');
Code:
include('config.php');
This PHP script will include config.php, letting the webpage with the include code use variables, connections etc from config.php

----------------------------------------------------------------------------------------------------------------------------------------------------

Echos and Variables
Code:
<?php echo $variable; ?>
This PHP script will find $variable in the current file or any included files and echo it. Echoing means to display, which you can see using the code.

----------------------------------------------------------------------------------------------------------------------------------------------------

Variables in config.php
Code:
<?php
$title = "Website";
$name = "Name";
?>
The above code defines each variable. In this case the code echo $title; would display Website

This is an extremely useful piece of code which can be used to make simple CMS's or websites. Hope this helps anyone, I tried making the tutorial as simple as I could to understand
 
Junior Spellweaver
Joined
Feb 14, 2007
Messages
106
Reaction score
0
Nice tutorial! I'm sure this will be useful for people that are trying to learn PHP.
 
Zzzz...
Loyal Member
Joined
Dec 26, 2008
Messages
781
Reaction score
225
Thanks :O I'll add some better ones later when I have time
 
Zzzz...
Loyal Member
Joined
Dec 26, 2008
Messages
781
Reaction score
225
Yeah, but for a newbie tutorial I think it should be fine
 
Joined
May 11, 2008
Messages
513
Reaction score
99
Do realize doing that means you'll have to declare them global in any functions to you make.

How would you do it so you don't have to do that, because I always do it this way, and like you've said, I have to declare it as global.
PHP:
<?php
class test
{
 private $issue, $tissue;
 public function __construct()
 {
   global $config, $db;
 }
}
 
Back
Top