I want all my hardcoded URL's will be saved in only 1 php file. Let's name it. Global.php so whenever I have hardcoded variable URLs. I will save it on my Global.php.
For example.
define("MAIN", "http://mainpage.com");
define("LOGIN", "http://mainpage.com/login");
define("REGISTER", "http://mainpage.com/register"):
So for example. I have a Login Page..
I will try to used the Global defined URL so It can avoid hardcoded URLS..
Login.php
include'../Global.php';
<ul>
<li><a href="<?php echo REGISTER; ?>">REGISTER</a></li>
<li><a href="<?php echo LOGIN; ?>">LOG IN</a></li>
</ul>
Like above, but the problem is on my Global.php. The domain name "http://mainpage.com" is repeatedly used in Global.. What I want to achieve is to set the domain name in Global.php and the subdomain and directory file of every pages should be concatenate to the Global define Domain only.. How I can do this?
I have research another solution like this:
define("LOGIN", "/login");
define("REGISTER", "/register"):
include'../Global.php';
<ul>
<li><a href="<?php echo REGISTER; ?>">REGISTER</a></li>
<li><a href="<?php echo LOGIN; ?>">LOG IN</a></li>
</ul>
But there are times that whenever I click the Register, It directs to
http://mainpage/REGISTER
which is supposedly directs to
http://mainpage/register
Sometimes it directs to http://mainpage/REGISTER
and sometimes it directs to http://mainpage/register
How I can avoid that?
I think what's best is.. for example..
In my Global.php I think I should declare the domain page and just concatenate the Global domain page in every subdomain page of my page..
Just like this..
define("MAIN", "http://mainpage/");
And I want to concatenate the global define domain in every page that I have hardcoded URLS. How I can achieve it?
For Example
On my index.php (MAINPAGE)
There is a button there that named LOGIN
and REGISTER
So in my code.. I want to be it like this..
include'../Global.php';
<ul>
<li><a href="<?php echo REGISTER . (Whatever subdomain name that register is and concatenate to global define domain); ?>">REGISTER</a></li>
<li><a href="<?php echo LOGIN . (Whatever subdomain name that login is and concatenate to global define domain); ?>">LOG IN</a></li>
</ul>
I have different page for LOGIN and REGISTER.. But I think, I was mistaken by concatenating the Global Define Domain to subdomain and directory file.. How to get the subdomain and directory file of a page and put it into a variable and concatenate it to the Global define
Can somebody help me?